private static ByteBuffer readToken(ByteBuffer bb) { final int start = bb.position(); int end = bb.limit(); while (bb.hasRemaining()) { if (!HttpParser.isToken(bb.get())) { end = bb.position() - 1; bb.position(end); break; } } return new ByteBuffer(bb.bytes, start, end - start); }
private static ByteBuffer readCookieValueRfc2109(ByteBuffer bb, boolean allowForwardSlash) { if (!bb.hasRemaining()) { return null; } if (bb.peek() == QUOTE_BYTE) { return readQuotedString(bb); } else { if (allowForwardSlash) { return readTokenAllowForwardSlash(bb); } else { return readToken(bb); } } }
private static SkipResult skipByte(ByteBuffer bb, byte target) { if (!bb.hasRemaining()) { return SkipResult.EOF; } if (bb.get() == target) { return SkipResult.FOUND; } bb.rewind(); return SkipResult.NOT_FOUND; }
static String readTokenOrQuotedString(Reader input, boolean returnQuoted) throws IOException { // Peek at next character to enable correct method to be called int c = skipLws(input); if (c == '"') { return readQuotedString(input, returnQuoted); } else { return readToken(input); } }
private static ByteBuffer readQuotedString(ByteBuffer bb) { int start = bb.position(); // Read the opening quote bb.get(); boolean escaped = false; while (bb.hasRemaining()) { byte b = bb.get(); if (b == SLASH_BYTE) { // Escaping another character escaped = true; } else if (escaped && b > (byte) -1) { escaped = false; } else if (b == QUOTE_BYTE) { return new ByteBuffer(bb.bytes, start, bb.position() - start); } else if (isText[b & 0xFF]) { escaped = false; } else { return null; } } return null; }
protected MediaType(String type, String subtype, LinkedHashMap<String,String> parameters) { this.type = type; this.subtype = subtype; this.parameters = parameters; String cs = parameters.get("charset"); if (cs != null && cs.length() > 0 && cs.charAt(0) == '"') { cs = HttpParser.unquote(cs); } this.charset = cs; }
private static SkipResult skipBytes(ByteBuffer bb, byte[] target) { int mark = bb.position(); for (int i = 0; i < target.length; i++) { if (!bb.hasRemaining()) { bb.position(mark); return SkipResult.EOF; } if (bb.get() != target[i]) { bb.position(mark); return SkipResult.NOT_FOUND; } } return SkipResult.FOUND; }
private static void skipUntilSemiColonOrComma(ByteBuffer bb) { while(bb.hasRemaining()) { byte b = bb.get(); if (b == SEMICOLON_BYTE || b == COMMA_BYTE) { break; } } }
/** * Parse the given input as a HTTP Host header value. * * @param mb The host header value * * @return The position of ':' that separates the host from the port or -1 * if it is not present * * @throws IllegalArgumentException If the host header value is not * specification compliant */ public static int parse(MessageBytes mb) { return parse(new MessageBytesReader(mb)); }
private static void skipInvalidCookie(ByteBuffer bb) { logInvalidHeader(bb); // Invalid cookie value. Skip to the next semi-colon skipUntilSemiColonOrComma(bb); }
public static boolean isAbsolutePath(int c) { return DEFAULT.isAbsolutePathRelaxed(c); }
public static boolean isQuery(int c) { return DEFAULT.isQueryRelaxed(c); }
public static boolean isNotRequestTarget(int c) { return DEFAULT.isNotRequestTargetRelaxed(c); }
/** * Parse the given input as a HTTP Host header value. * * @param string The host header value * * @return The position of ':' that separates the host from the port or -1 * if it is not present * * @throws IllegalArgumentException If the host header value is not * specification compliant */ public static int parse(String string) { return parse(new StringReader(string)); }
private void relax(boolean[] flags, String relaxedChars) { if (relaxedChars != null && relaxedChars.length() > 0) { char[] chars = relaxedChars.toCharArray(); for (char c : chars) { if (isRelaxable(c)) { flags[c] = true; IS_NOT_REQUEST_TARGET[c] = false; } } } }
private static String readTokenOrQuotedString(StringReader input, boolean returnQuoted) throws IOException { // Go back so first non-LWS character is available to be read again int c = skipLws(input, true); if (c == '"') { return readQuotedString(input, returnQuoted); } else { return readToken(input); } }
private static ByteBuffer readTokenAllowForwardSlash(ByteBuffer bb) { final int start = bb.position(); int end = bb.limit(); while (bb.hasRemaining()) { byte b = bb.get(); if (b != FORWARDSLASH_BYTE && !HttpParser.isToken(b)) { end = bb.position() - 1; bb.position(end); break; } } return new ByteBuffer(bb.bytes, start, end - start); }
private static void skipLWS(ByteBuffer bb) { while(bb.hasRemaining()) { byte b = bb.get(); if (b != TAB_BYTE && b != SPACE_BYTE) { bb.rewind(); break; } } }
private static void skipUntilSemiColon(ByteBuffer bb) { while(bb.hasRemaining()) { if (bb.get() == SEMICOLON_BYTE) { break; } } }
private static String readTokenOrQuotedString(StringReader input, boolean returnQuoted) throws IOException { // Go back so first non-LWS character is available to be read again int c = skipLws(input, true); if (c == '"') { return readQuotedString(input, returnQuoted); } else { return readToken(input); } }