Search in sources :

Example 71 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.

the class BasicHeaderValueParser method parseElements.

// public default constructor
/**
     * 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 static final 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);
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 72 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.

the class BasicLineFormatter method formatStatusLine.

// non-javadoc, see interface LineFormatter
public CharArrayBuffer formatStatusLine(final CharArrayBuffer buffer, final StatusLine statline) {
    if (statline == null) {
        throw new IllegalArgumentException("Status line may not be null");
    }
    CharArrayBuffer result = initBuffer(buffer);
    doFormatStatusLine(result, statline);
    return result;
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 73 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.

the class BasicLineFormatter method formatRequestLine.

// non-javadoc, see interface LineFormatter
public CharArrayBuffer formatRequestLine(CharArrayBuffer buffer, RequestLine reqline) {
    if (reqline == null) {
        throw new IllegalArgumentException("Request line may not be null");
    }
    CharArrayBuffer result = initBuffer(buffer);
    doFormatRequestLine(result, reqline);
    return result;
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 74 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.

the class AndroidHttpClientConnection method parseResponseHeader.

/**
     * Parses the response headers and adds them to the
     * given {@code headers} object, and returns the response StatusLine
     * @param headers store parsed header to headers.
     * @throws IOException
     * @return StatusLine
     * @see HttpClientConnection#receiveResponseHeader()
      */
public StatusLine parseResponseHeader(Headers headers) throws IOException, ParseException {
    assertOpen();
    CharArrayBuffer current = new CharArrayBuffer(64);
    if (inbuffer.readLine(current) == -1) {
        throw new NoHttpResponseException("The target server failed to respond");
    }
    // Create the status line from the status string
    StatusLine statusline = BasicLineParser.DEFAULT.parseStatusLine(current, new ParserCursor(0, current.length()));
    if (HttpLog.LOGV)
        HttpLog.v("read: " + statusline);
    int statusCode = statusline.getStatusCode();
    // Parse header body
    CharArrayBuffer previous = null;
    int headerNumber = 0;
    while (true) {
        if (current == null) {
            current = new CharArrayBuffer(64);
        } else {
            // This must be he buffer used to parse the status
            current.clear();
        }
        int l = inbuffer.readLine(current);
        if (l == -1 || current.length() < 1) {
            break;
        }
        // Parse the header name and value
        // Check for folded headers first
        // Detect LWS-char see HTTP/1.0 or HTTP/1.1 Section 2.2
        // discussion on folded headers
        char first = current.charAt(0);
        if ((first == ' ' || first == '\t') && previous != null) {
            // we have continuation folded header
            // so append value
            int start = 0;
            int length = current.length();
            while (start < length) {
                char ch = current.charAt(start);
                if (ch != ' ' && ch != '\t') {
                    break;
                }
                start++;
            }
            if (maxLineLength > 0 && previous.length() + 1 + current.length() - start > maxLineLength) {
                throw new IOException("Maximum line length limit exceeded");
            }
            previous.append(' ');
            previous.append(current, start, current.length() - start);
        } else {
            if (previous != null) {
                headers.parseHeader(previous);
            }
            headerNumber++;
            previous = current;
            current = null;
        }
        if (maxHeaderCount > 0 && headerNumber >= maxHeaderCount) {
            throw new IOException("Maximum header count exceeded");
        }
    }
    if (previous != null) {
        headers.parseHeader(previous);
    }
    if (statusCode >= 200) {
        this.metrics.incrementResponseCount();
    }
    return statusline;
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) StatusLine(org.apache.http.StatusLine) ParserCursor(org.apache.http.message.ParserCursor) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) IOException(java.io.IOException)

Example 75 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.

the class HttpHost method toURI.

/**
     * Return the host URI, as a string.
     * 
     * @return the host URI
     */
public String toURI() {
    CharArrayBuffer buffer = new CharArrayBuffer(32);
    buffer.append(this.schemeName);
    buffer.append("://");
    buffer.append(this.hostname);
    if (this.port != -1) {
        buffer.append(':');
        buffer.append(Integer.toString(this.port));
    }
    return buffer.toString();
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Aggregations

CharArrayBuffer (org.apache.http.util.CharArrayBuffer)126 BufferedHeader (org.apache.http.message.BufferedHeader)27 FormattedHeader (org.apache.http.FormattedHeader)24 Header (org.apache.http.Header)21 ArrayList (java.util.ArrayList)19 ClientCookie (org.apache.http.cookie.ClientCookie)12 Cookie (org.apache.http.cookie.Cookie)12 ParserCursor (org.apache.http.message.ParserCursor)11 Headers (android.net.http.Headers)6 IOException (java.io.IOException)6 MalformedChallengeException (org.apache.http.auth.MalformedChallengeException)6 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)6 AuthenticationException (org.apache.http.auth.AuthenticationException)5 InvalidCredentialsException (org.apache.http.auth.InvalidCredentialsException)5 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)5 NTCredentials (org.apache.http.auth.NTCredentials)4 HashMap (java.util.HashMap)3 HeaderElement (org.apache.http.HeaderElement)3 NoHttpResponseException (org.apache.http.NoHttpResponseException)3 ParseException (org.apache.http.ParseException)3