public BufRange first() { return get(0); }
public BufRange last() { return get(count - 1); }
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; } }
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); }
public BufRange first() { return get(0); }
public BufRange last() { return get(count - 1); }
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; } }
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); }