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; } } } }
/** * Gets a header representing all of the header values with the given name. * If more that one header with the given name exists the values will be * combined with a "," as per RFC 2616. * * <p>Header name comparison is case insensitive. * * @param name the name of the header(s) to get * @return a header with a condensed value or <code>null</code> if no * headers by the given name are present */ public Header getCondensedHeader(String name) { Header[] headers = getHeaders(name); if (headers.length == 0) { return null; } else if (headers.length == 1) { return headers[0]; } else { CharArrayBuffer valueBuffer = new CharArrayBuffer(128); valueBuffer.append(headers[0].getValue()); for (int i = 1; i < headers.length; i++) { valueBuffer.append(", "); valueBuffer.append(headers[i].getValue()); } return new BasicHeader(name.toLowerCase(Locale.ENGLISH), valueBuffer.toString()); } }
char ch = buffer.charAt(pos); if (ch == '=') { break; name = buffer.substringTrimmed(indexFrom, indexTo); } else { name = buffer.substringTrimmed(indexFrom, pos); pos++; boolean escaped = false; while (pos < indexTo) { char ch = buffer.charAt(pos); if (ch == '"' && !escaped) { qouted = !qouted; while (i1 < i2 && (HTTP.isWhitespace(buffer.charAt(i1)))) { i1++; while ((i2 > i1) && (HTTP.isWhitespace(buffer.charAt(i2 - 1)))) { i2--; && (buffer.charAt(i1) == '"') && (buffer.charAt(i2 - 1) == '"')) { i1++; i2--; value = buffer.substring(i1, i2); if (terminated) { pos++;
public String toString() { CharArrayBuffer buffer = new CharArrayBuffer(64); buffer.append(this.name); if (this.value != null) { buffer.append("="); buffer.append(this.value); } for (int i = 0; i < this.parameters.length; i++) { buffer.append("; "); buffer.append(this.parameters[i]); } return buffer.toString(); }
public String getValue() { return this.buffer.substringTrimmed(this.valuePos, this.buffer.length()); }
/** * Obtains a buffer for formatting. * * @param buffer a buffer already available, or <code>null</code> * * @return the cleared argument buffer if there is one, or * a new empty buffer that can be used for formatting */ protected CharArrayBuffer initBuffer(CharArrayBuffer buffer) { if (buffer != null) { buffer.clear(); } else { buffer = new CharArrayBuffer(64); } return buffer; }
int pos; if (header instanceof FormattedHeader) { buffer = ((FormattedHeader) header).getBuffer(); pos = ((FormattedHeader) header).getValuePos(); } else { String s = header.getValue(); if (s == null) { throw new MalformedChallengeException("Header value is null"); buffer = new CharArrayBuffer(s.length()); buffer.append(s); pos = 0; while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos))) { pos++; while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) { pos++; String s = buffer.substring(beginIndex, endIndex); map.put(s.toLowerCase(Locale.ENGLISH), header);
/** * Actually formats a header. * Called from {@link #formatHeader}. * * @param buffer the empty buffer into which to format, * never <code>null</code> * @param header the header to format, never <code>null</code> */ protected void doFormatHeader(final CharArrayBuffer buffer, final Header header) { final String name = header.getName(); final String value = header.getValue(); int len = name.length() + 2; if (value != null) { len += value.length(); } buffer.ensureCapacity(len); buffer.append(name); buffer.append(": "); if (value != null) { buffer.append(value); } }
@Override public Header authenticate(Credentials credentials, HttpRequest request) throws AuthenticationException { Credentials ntCredentials = credentials; if (!(credentials instanceof NTCredentials)) { ntCredentials = new NTCredentials(credentials.getUserPrincipal().getName() + ":" + credentials.getPassword()); } Header header = super.authenticate(ntCredentials, request); //need replace NTLM with Negotiate CharArrayBuffer buffer = new CharArrayBuffer(512); buffer.append(header.getName()); buffer.append(": "); buffer.append(header.getValue().replaceFirst("NTLM", "Negotiate")); return new BufferedHeader(buffer); } }
/** * Write header to headerBuffer in an optimized way * @param headerBuffer {@link StringBuilder} * @param header {@link Header} */ private void writeHeader(StringBuilder headerBuffer, Header header) { if(header instanceof BufferedHeader) { CharArrayBuffer buffer = ((BufferedHeader)header).getBuffer(); headerBuffer.append(buffer.buffer(), 0, buffer.length()).append('\n'); // $NON-NLS-1$ } else { headerBuffer.append(header.getName()) .append(": ") // $NON-NLS-1$ .append(header.getValue()) .append('\n'); // $NON-NLS-1$ } }
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); }
@Override public Header getVersionHeader() { CharArrayBuffer buffer = new CharArrayBuffer(40); buffer.append(SM.COOKIE2); buffer.append(": "); buffer.append("$Version="); buffer.append(Integer.toString(getVersion())); return new BufferedHeader(buffer); }
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); }
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 HeaderElement[] getElements() throws ParseException { ParserCursor cursor = new ParserCursor(0, this.buffer.length()); cursor.updatePos(this.valuePos); return BasicHeaderValueParser.DEFAULT .parseElements(this.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); }
for (;;) { if (current == null) { current = new CharArrayBuffer(64); } else { current.clear(); int l = inbuffer.readLine(current); if (l == -1 || current.length() < 1) { break; if ((current.charAt(0) == ' ' || current.charAt(0) == '\t') && previous != null) { while (i < current.length()) { char ch = current.charAt(i); if (ch != ' ' && ch != '\t') { break; && previous.length() + 1 + current.length() - i > maxLineLen) { throw new IOException("Maximum line length limit exceeded"); previous.append(' '); previous.append(current, i, current.length() - i); } else { headerLines.add(current);
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); }
/** * 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); }
@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()); } }