@Override public String toString() { return isEmpty() ? "[]" : "[" + start + ":" + length + "]"; }
private String validateRequest(Buf input, BufRange verb, BufRange uri) { if (verb.isEmpty()) { return "HTTP verb cannot be empty!"; } if (!BytesUtil.isValidURI(input.bytes(), uri)) { return "Invalid HTTP URI!"; } return null; // OK, no error }
@Override public synchronized String get() { if (value == null) { value = !range.isEmpty() ? src.buffer().get(range) : ""; } return value; }
@Override public String get(BufRange range) { assert invariant(false); if (range.isEmpty()) { return ""; } byte[] bytes = new byte[range.length]; int total = readAll(bytes, 0, range.start, range.length); assert total == bytes.length; assert invariant(false); return new String(bytes); }
private boolean isJSON(Buf src, BufRanges contentTypes, int index) { if (contentTypes.count > 0) { U.must(contentTypes.count > index); BufRange ct = contentTypes.get(index); return !ct.isEmpty() && ct.str(src.bytes()).startsWith("application/json"); } else { return false; } }
@Override public synchronized String get() { if (value == null) { value = !range.isEmpty() ? URIs.urlDecode(src.buffer().get(range)) : ""; } return value; }
public void parseHeadersIntoKV(Buf buf, BufRanges headers, KeyValueRanges headersKV, KeyValueRanges cookies, RapidoidHelper helper) { BufRange cookie = helper.ranges5.ranges[0]; for (int i = 0; i < headers.count; i++) { BufRange hdr = headers.ranges[i]; int ind = headersKV.add(); BufRange key = headersKV.keys[ind]; BufRange val = headersKV.values[ind]; assert !hdr.isEmpty(); boolean split = BytesUtil.split(buf.bytes(), hdr, COL, key, val, true); U.must(split, "Invalid HTTP header!"); if (cookies != null && BytesUtil.matches(buf.bytes(), key, COOKIE, false)) { headersKV.count--; // don't include cookies in headers do { BytesUtil.split(buf.bytes(), val, SEMI_COL, cookie, val, true); int cind = cookies.add(); BytesUtil.split(buf.bytes(), cookie, EQ, cookies.keys[cind], cookies.values[cind], true); } while (!val.isEmpty()); } } }
private boolean detectKeepAlive(Buf buf, RapidoidHelper helper, Bytes bytes, BufRange protocol, BufRanges headers) { IntWrap result = helper.integers[0]; boolean keepAliveByDefault = protocol.isEmpty() || bytes.get(protocol.last()) != '0'; // e.g. HTTP/1.1 // try to detect the opposite of the default if (keepAliveByDefault) { buf.scanLnLn(headers.reset(), result, (byte) 's', (byte) 'e'); // clo[se] } else { buf.scanLnLn(headers.reset(), result, (byte) 'v', (byte) 'e'); // keep-ali[ve] } int possibleConnHeaderPos = result.value; if (possibleConnHeaderPos < 0) return keepAliveByDefault; // no evidence of the opposite BufRange possibleConnHdr = headers.get(possibleConnHeaderPos); if (BytesUtil.startsWith(bytes, possibleConnHdr, CONNECTION, true)) { return !keepAliveByDefault; // detected the opposite of the default } return isKeepAlive(bytes, headers, helper, keepAliveByDefault); }
boolean pendingBodyParsing = false; if (!isGet && !helper.body.isEmpty()) { KeyValueRanges postedKV = helper.pairs3.reset();
if (filename.isEmpty()) { int ind = data.add(); data.keys[ind].assign(name);
@Override public String toString() { return isEmpty() ? "[]" : "[" + start + ":" + length + "]"; }
private String validateRequest(Buf input, BufRange verb, BufRange uri) { if (verb.isEmpty()) { return "HTTP verb cannot be empty!"; } if (!BytesUtil.isValidURI(input.bytes(), uri)) { return "Invalid HTTP URI!"; } return null; // OK, no error }
@Override public String get(BufRange range) { assert invariant(false); if (range.isEmpty()) { return ""; } byte[] bytes = new byte[range.length]; int total = readAll(bytes, 0, range.start, range.length); assert total == bytes.length; assert invariant(false); return new String(bytes); }
private boolean isJSON(Buf src, BufRanges contentTypes, int index) { if (contentTypes.count > 0) { U.must(contentTypes.count > index); BufRange ct = contentTypes.get(index); return !ct.isEmpty() && ct.str(src.bytes()).startsWith("application/json"); } else { return false; } }
public void parseHeadersIntoKV(Buf buf, BufRanges headers, KeyValueRanges headersKV, KeyValueRanges cookies, RapidoidHelper helper) { BufRange cookie = helper.ranges5.ranges[0]; for (int i = 0; i < headers.count; i++) { BufRange hdr = headers.ranges[i]; int ind = headersKV.add(); BufRange key = headersKV.keys[ind]; BufRange val = headersKV.values[ind]; assert !hdr.isEmpty(); boolean split = BytesUtil.split(buf.bytes(), hdr, COL, key, val, true); U.must(split, "Invalid HTTP header!"); if (cookies != null && BytesUtil.matches(buf.bytes(), key, COOKIE, false)) { headersKV.count--; // don't include cookies in headers do { BytesUtil.split(buf.bytes(), val, SEMI_COL, cookie, val, true); int cind = cookies.add(); BytesUtil.split(buf.bytes(), cookie, EQ, cookies.keys[cind], cookies.values[cind], true); } while (!val.isEmpty()); } } }
private boolean detectKeepAlive(Buf buf, RapidoidHelper helper, Bytes bytes, BufRange protocol, BufRanges headers) { IntWrap result = helper.integers[0]; boolean keepAliveByDefault = protocol.isEmpty() || bytes.get(protocol.last()) != '0'; // e.g. HTTP/1.1 // try to detect the opposite of the default if (keepAliveByDefault) { buf.scanLnLn(headers.reset(), result, (byte) 's', (byte) 'e'); // clo[se] } else { buf.scanLnLn(headers.reset(), result, (byte) 'v', (byte) 'e'); // keep-ali[ve] } int possibleConnHeaderPos = result.value; if (possibleConnHeaderPos < 0) return keepAliveByDefault; // no evidence of the opposite BufRange possibleConnHdr = headers.get(possibleConnHeaderPos); if (BytesUtil.startsWith(bytes, possibleConnHdr, CONNECTION, true)) { return !keepAliveByDefault; // detected the opposite of the default } return isKeepAlive(bytes, headers, helper, keepAliveByDefault); }
boolean pendingBodyParsing = false; if (!isGet && !helper.body.isEmpty()) { KeyValueRanges postedKV = helper.pairs3.reset();
if (filename.isEmpty()) { int ind = data.add(); data.keys[ind].assign(name);