Search in sources :

Example 1 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project android_frameworks_base by ParanoidAndroid.

the class HttpHeaderTest method testCacheControl.

/**
     * Tests that cache control header supports multiple instances of the header,
     * according to HTTP specification.
     *
     * The HTTP specification states the following about the fields:
     * Multiple message-header fields with the same field-name MAY be present
     * in a message if and only if the entire field-value for that header field
     * is defined as a comma-separated list [i.e., #(values)]. It MUST be
     * possible to combine the multiple header fields into one "field-name:
     * field-value" pair, without changing the semantics of the message, by
     * appending each subsequent field-value to the first, each separated by a
     * comma. The order in which header fields with the same field-name are
     * received is therefore significant to the interpretation of the combined
     * field value, and thus a proxy MUST NOT change the order of these field
     * values when a message is forwarded.
     */
public void testCacheControl() throws Exception {
    Headers h = new Headers();
    CharArrayBuffer buffer = new CharArrayBuffer(64);
    buffer.append(CACHE_CONTROL_MAX_AGE);
    h.parseHeader(buffer);
    buffer.clear();
    buffer.append(LAST_MODIFIED);
    h.parseHeader(buffer);
    assertEquals("max-age=15", h.getCacheControl());
    buffer.clear();
    buffer.append(CACHE_CONTROL_PRIVATE);
    h.parseHeader(buffer);
    assertEquals("max-age=15,private", h.getCacheControl());
}
Also used : Headers(android.net.http.Headers) CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 2 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project android_frameworks_base by ParanoidAndroid.

the class HttpHeaderTest method testCacheControlMultipleArguments.

// Test that cache behaves correctly when receiving a compund
// cache-control statement containing no-cache and max-age argument.
//
// If a cache control header contains both a max-age arument and
// a no-cache argument the max-age argument should be ignored.
// The resource can be cached, but a validity check must be done on
// every request. Test case checks that the expiry time is 0 for
// this item, so item will be validated on subsequent requests.
public void testCacheControlMultipleArguments() throws Exception {
    // get private method CacheManager.parseHeaders()
    Method m = CacheManager.class.getDeclaredMethod("parseHeaders", new Class[] { int.class, Headers.class, String.class });
    m.setAccessible(true);
    // create indata
    Headers h = new Headers();
    CharArrayBuffer buffer = new CharArrayBuffer(64);
    buffer.append(CACHE_CONTROL_COMPOUND);
    h.parseHeader(buffer);
    CacheResult c = (CacheResult) m.invoke(null, 200, h, "text/html");
    // Check that expires is set to 0, to ensure that no-cache has overridden
    // the max-age argument
    assertEquals(0, c.getExpires());
    // check reverse order
    buffer.clear();
    buffer.append(CACHE_CONTROL_COMPOUND2);
    h.parseHeader(buffer);
    c = (CacheResult) m.invoke(null, 200, h, "text/html");
    assertEquals(0, c.getExpires());
}
Also used : Headers(android.net.http.Headers) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) CacheResult(android.webkit.CacheManager.CacheResult) Method(java.lang.reflect.Method)

Example 3 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project android_frameworks_base by ParanoidAndroid.

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 4 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project android_frameworks_base by DirtyUnicorns.

the class HttpHeaderTest method testCacheControl.

/**
     * Tests that cache control header supports multiple instances of the header,
     * according to HTTP specification.
     *
     * The HTTP specification states the following about the fields:
     * Multiple message-header fields with the same field-name MAY be present
     * in a message if and only if the entire field-value for that header field
     * is defined as a comma-separated list [i.e., #(values)]. It MUST be
     * possible to combine the multiple header fields into one "field-name:
     * field-value" pair, without changing the semantics of the message, by
     * appending each subsequent field-value to the first, each separated by a
     * comma. The order in which header fields with the same field-name are
     * received is therefore significant to the interpretation of the combined
     * field value, and thus a proxy MUST NOT change the order of these field
     * values when a message is forwarded.
     */
public void testCacheControl() throws Exception {
    Headers h = new Headers();
    CharArrayBuffer buffer = new CharArrayBuffer(64);
    buffer.append(CACHE_CONTROL_MAX_AGE);
    h.parseHeader(buffer);
    buffer.clear();
    buffer.append(LAST_MODIFIED);
    h.parseHeader(buffer);
    assertEquals("max-age=15", h.getCacheControl());
    buffer.clear();
    buffer.append(CACHE_CONTROL_PRIVATE);
    h.parseHeader(buffer);
    assertEquals("max-age=15,private", h.getCacheControl());
}
Also used : Headers(android.net.http.Headers) CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 5 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project robovm by robovm.

the class RFC2965Spec method getVersionHeader.

@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);
}
Also used : BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Aggregations

CharArrayBuffer (org.apache.http.util.CharArrayBuffer)129 BufferedHeader (org.apache.http.message.BufferedHeader)28 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 ParseException (org.apache.http.ParseException)4 NTCredentials (org.apache.http.auth.NTCredentials)4 HashMap (java.util.HashMap)3 HeaderElement (org.apache.http.HeaderElement)3 NoHttpResponseException (org.apache.http.NoHttpResponseException)3