void removeTrailingSlash(Buf buf, BufRange range) { if (range.length > 1 && buf.get(range.last()) == '/') { range.length--; } }
public static boolean matches(Bytes bytes, BufRange target, byte[] match, boolean caseSensitive) { if (target.length != match.length || target.start < 0 || target.last() >= bytes.limit()) { return false; } boolean result = match(bytes, target.start, match, caseSensitive); return result; }
public static boolean startsWith(Bytes bytes, BufRange target, byte[] match, boolean caseSensitive) { if (target.length < match.length || target.start < 0 || target.last() >= bytes.limit()) { return false; } boolean result = match(bytes, target.start, match, caseSensitive); return result; }
public static boolean containsAt(Bytes bytes, BufRange target, int offset, byte[] match, boolean caseSensitive) { if (offset < 0 || target.length < offset + match.length || target.start < 0 || target.last() >= bytes.limit()) { return false; } boolean result = match(bytes, target.start + offset, match, caseSensitive); return result; }
public static boolean isValidURI(Bytes bytes, BufRange uri) { int start = uri.start; int len = uri.length; int last = uri.last(); if (len == 0 || bytes.get(start) != '/') { return false; } boolean inPath = true; byte prev = '/'; for (int p = start + 1; p <= last; p++) { byte b = bytes.get(p); if (b <= 0 || !URI_ALLOWED_CHARACTER[b]) { return false; } // disallow '..' OR '//' in the URI's PATH (before the '?') if (inPath) { if (b == '.' || b == '/') { if (prev == b) { return false; } } else if (b == '?') { inPath = false; } } prev = b; } return true; }
private long hash(Bytes bytes, BufRange key) { int prefix = BytesUtil.getIntPrefixOf(bytes, key.start, key.limit()); return prefix * 17 + key.length * 19 + bytes.get(key.last()); }
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); }
void removeTrailingSlash(Buf buf, BufRange range) { if (range.length > 1 && buf.get(range.last()) == '/') { range.length--; } }
public static boolean startsWith(Bytes bytes, BufRange target, byte[] match, boolean caseSensitive) { if (target.length < match.length || target.start < 0 || target.last() >= bytes.limit()) { return false; } boolean result = match(bytes, target.start, match, caseSensitive); return result; }
public static boolean matches(Bytes bytes, BufRange target, byte[] match, boolean caseSensitive) { if (target.length != match.length || target.start < 0 || target.last() >= bytes.limit()) { return false; } boolean result = match(bytes, target.start, match, caseSensitive); return result; }
public static boolean containsAt(Bytes bytes, BufRange target, int offset, byte[] match, boolean caseSensitive) { if (offset < 0 || target.length < offset + match.length || target.start < 0 || target.last() >= bytes.limit()) { return false; } boolean result = match(bytes, target.start + offset, match, caseSensitive); return result; }
private long hash(Bytes bytes, BufRange key) { int prefix = BytesUtil.getIntPrefixOf(bytes, key.start, key.limit()); return prefix * 17 + key.length * 19 + bytes.get(key.last()); }
public static boolean isValidURI(Bytes bytes, BufRange uri) { int start = uri.start; int len = uri.length; int last = uri.last(); if (len == 0 || bytes.get(start) != '/') { return false; } boolean inPath = true; byte prev = '/'; for (int p = start + 1; p <= last; p++) { byte b = bytes.get(p); if (b <= 0 || !URI_ALLOWED_CHARACTER[b]) { return false; } // disallow '..' OR '//' in the URI's PATH (before the '?') if (inPath) { if (b == '.' || b == '/') { if (prev == b) { return false; } } else if (b == '?') { inPath = false; } } prev = b; } return true; }
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); }