protected HttpMessage parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException { this.lineBuf.clear(); int i = sessionBuffer.readLine(this.lineBuf); if (i == -1) { throw new NoHttpResponseException("The target server failed to respond"); } //create the status line from the status string ParserCursor cursor = new ParserCursor(0, this.lineBuf.length()); StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor); return this.responseFactory.newHttpResponse(statusline, null); }
public HeaderElement parseHeaderElement(final CharArrayBuffer buffer, final ParserCursor cursor) { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } NameValuePair nvp = parseNameValuePair(buffer, cursor); NameValuePair[] params = null; if (!cursor.atEnd()) { char ch = buffer.charAt(cursor.getPos() - 1); if (ch != ELEM_DELIMITER) { params = parseParameters(buffer, cursor); } } return createHeaderElement(nvp.getName(), nvp.getValue(), params); }
/** * Helper to skip whitespace. */ protected void skipWhitespace(final CharArrayBuffer buffer, final ParserCursor cursor) { int pos = cursor.getPos(); int indexTo = cursor.getUpperBound(); while ((pos < indexTo) && HTTP.isWhitespace(buffer.charAt(pos))) { pos++; } cursor.updatePos(pos); }
public HeaderElement[] getElements() throws ParseException { ParserCursor cursor = new ParserCursor(0, this.buffer.length()); cursor.updatePos(this.valuePos); return BasicHeaderValueParser.DEFAULT .parseElements(this.buffer, cursor); }
public final static RequestLine parseRequestLine(final String value, LineParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null."); } if (parser == null) parser = BasicLineParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseRequestLine(buffer, cursor); }
public final static StatusLine parseStatusLine(final String value, LineParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null."); } if (parser == null) parser = BasicLineParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseStatusLine(buffer, cursor); }
public final static ProtocolVersion parseProtocolVersion(String value, LineParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null."); } if (parser == null) parser = BasicLineParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseProtocolVersion(buffer, cursor); }
protected HttpMessage parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException { this.lineBuf.clear(); int i = sessionBuffer.readLine(this.lineBuf); if (i == -1) { throw new ConnectionClosedException("Client closed connection"); } ParserCursor cursor = new ParserCursor(0, this.lineBuf.length()); RequestLine requestline = this.lineParser.parseRequestLine(this.lineBuf, cursor); return this.requestFactory.newHttpRequest(requestline); }
private void bufferHeaderValue() { this.cursor = null; this.buffer = null; while (this.headerIt.hasNext()) { Header h = this.headerIt.nextHeader(); if (h instanceof FormattedHeader) { this.buffer = ((FormattedHeader) h).getBuffer(); this.cursor = new ParserCursor(0, this.buffer.length()); this.cursor.updatePos(((FormattedHeader) h).getValuePos()); break; } else { String value = h.getValue(); if (value != null) { this.buffer = new CharArrayBuffer(value.length()); this.buffer.append(value); this.cursor = new ParserCursor(0, this.buffer.length()); break; } } } }
@Override protected void parseChallenge( final CharArrayBuffer buffer, int pos, int len) throws MalformedChallengeException { HeaderValueParser parser = BasicHeaderValueParser.DEFAULT; ParserCursor cursor = new ParserCursor(pos, buffer.length()); HeaderElement[] elements = parser.parseElements(buffer, cursor); if (elements.length == 0) { throw new MalformedChallengeException("Authentication challenge is empty"); } this.params = new HashMap<String, String>(elements.length); for (HeaderElement element : elements) { this.params.put(element.getName(), element.getValue()); } }
/** * Parses elements with the given parser. * * @param value the header value to parse * @param parser the parser to use, or <code>null</code> for default * * @return array holding the header elements, never <code>null</code> */ public final static HeaderElement[] parseElements(final String value, HeaderValueParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicHeaderValueParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseElements(buffer, cursor); }
/** * Parses a name-value-pair with the given parser. * * @param value the NVP to parse * @param parser the parser to use, or <code>null</code> for default * * @return the parsed name-value pair */ public final static NameValuePair parseNameValuePair(final String value, HeaderValueParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicHeaderValueParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseNameValuePair(buffer, cursor); }
/** * Parses an element with the given parser. * * @param value the header element to parse * @param parser the parser to use, or <code>null</code> for default * * @return the parsed header element */ public final static HeaderElement parseHeaderElement(final String value, HeaderValueParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicHeaderValueParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseHeaderElement(buffer, cursor); }
/** * Parses parameters with the given parser. * * @param value the parameter list to parse * @param parser the parser to use, or <code>null</code> for default * * @return array holding the parameters, never <code>null</code> */ public final static NameValuePair[] parseParameters(final String value, HeaderValueParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicHeaderValueParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseParameters(buffer, cursor); }
int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); char ch = buffer.charAt(pos); if (ch == '=') { break; if (isOneOf(ch, delimiters)) { terminated = true; break; cursor.updatePos(pos); return createNameValuePair(name, null); qouted = !qouted; if (!qouted && !escaped && isOneOf(ch, delimiters)) { terminated = true; break; pos++; cursor.updatePos(pos); return createNameValuePair(name, value);
int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); int i = cursor.getPos(); int blank = buffer.indexOf(' ', i, indexTo); if (blank < 0) { throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo)); String method = buffer.substringTrimmed(i, blank); cursor.updatePos(blank); i = cursor.getPos(); blank = buffer.indexOf(' ', i, indexTo); String uri = buffer.substringTrimmed(i, blank); cursor.updatePos(blank); if (!cursor.atEnd()) { throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo));
final int protolength = protoname.length(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); int i = cursor.getPos(); throw new ParseException ("Not a valid protocol version: " + buffer.substring(indexFrom, indexTo)); ok = (buffer.charAt(i+j) == protoname.charAt(j)); ok = (buffer.charAt(i+protolength) == '/'); cursor.updatePos(blank);
int pos = cursor.getPos(); int indexTo = cursor.getUpperBound(); char ch = buffer.charAt(pos); if (HTTP.isWhitespace(ch)) { pos++; cursor.updatePos(pos); if (cursor.atEnd()) { return new NameValuePair[] {}; while (!cursor.atEnd()) { NameValuePair param = parseNameValuePair(buffer, cursor); params.add(param); char ch = buffer.charAt(cursor.getPos() - 1); if (ch == ELEM_DELIMITER) { break;
@Override protected HttpResponse createMessage(final CharArrayBuffer buffer) throws HttpException, ParseException { final ParserCursor cursor = new ParserCursor(0, buffer.length()); final StatusLine statusline = lineParser.parseStatusLine(buffer, cursor); return this.responseFactory.newHttpResponse(statusline, null); }
int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); int i = cursor.getPos(); int blank = buffer.indexOf(' ', i, indexTo); if (blank < 0) { blank = indexTo; try { statusCode = Integer.parseInt(buffer.substringTrimmed(i, blank)); } catch (NumberFormatException e) { throw new ParseException( "Unable to parse status code from status line: " + buffer.substring(indexFrom, indexTo));