Search in sources :

Example 91 with CharArrayBuffer

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

the class BrowserCompatSpec method formatCookies.

public List<Header> formatCookies(final List<Cookie> cookies) {
    if (cookies == null) {
        throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
        throw new IllegalArgumentException("List of cookies may not be empty");
    }
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        buffer.append(cookie.getName());
        buffer.append("=");
        String s = cookie.getValue();
        if (s != null) {
            buffer.append(s);
        }
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) Cookie(org.apache.http.cookie.Cookie) BufferedHeader(org.apache.http.message.BufferedHeader) Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList)

Example 92 with CharArrayBuffer

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

the class NetscapeDraftSpec method formatCookies.

public List<Header> formatCookies(final List<Cookie> cookies) {
    if (cookies == null) {
        throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
        throw new IllegalArgumentException("List of cookies may not be empty");
    }
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        buffer.append(cookie.getName());
        String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) Cookie(org.apache.http.cookie.Cookie) BufferedHeader(org.apache.http.message.BufferedHeader) Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList)

Example 93 with CharArrayBuffer

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

the class RFC2109Spec method doFormatOneHeader.

private List<Header> doFormatOneHeader(final List<Cookie> cookies) {
    int version = Integer.MAX_VALUE;
    // Pick the lowest common denominator
    for (Cookie cookie : cookies) {
        if (cookie.getVersion() < version) {
            version = cookie.getVersion();
        }
    }
    CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(version));
    for (Cookie cooky : cookies) {
        buffer.append("; ");
        Cookie cookie = cooky;
        formatCookieAsVer(buffer, cookie, version);
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) Cookie(org.apache.http.cookie.Cookie) BufferedHeader(org.apache.http.message.BufferedHeader) Header(org.apache.http.Header) BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList)

Example 94 with CharArrayBuffer

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

the class RFC2109Spec method doFormatManyHeaders.

private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
    List<Header> headers = new ArrayList<Header>(cookies.size());
    for (Cookie cookie : cookies) {
        int version = cookie.getVersion();
        CharArrayBuffer buffer = new CharArrayBuffer(40);
        buffer.append("Cookie: ");
        buffer.append("$Version=");
        buffer.append(Integer.toString(version));
        buffer.append("; ");
        formatCookieAsVer(buffer, cookie, version);
        headers.add(new BufferedHeader(buffer));
    }
    return headers;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) Cookie(org.apache.http.cookie.Cookie) BufferedHeader(org.apache.http.message.BufferedHeader) Header(org.apache.http.Header) BufferedHeader(org.apache.http.message.BufferedHeader) ArrayList(java.util.ArrayList) CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 95 with CharArrayBuffer

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

the class AbstractMessageParser method parseHeaders.

/**
     * Parses HTTP headers from the data receiver stream according to the generic 
     * format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.
     *  
     * @param inbuffer Session input buffer
     * @param maxHeaderCount maximum number of headers allowed. If the number
     *  of headers received from the data stream exceeds maxCount value, an
     *  IOException will be thrown. Setting this parameter to a negative value
     *  or zero  will disable the check.
     * @param maxLineLen maximum number of characters for a header line,
     *                   including the continuation lines
     * @return array of HTTP headers
     * 
     * @throws HttpException
     * @throws IOException
     */
public static Header[] parseHeaders(final SessionInputBuffer inbuffer, int maxHeaderCount, int maxLineLen, LineParser parser) throws HttpException, IOException {
    if (inbuffer == null) {
        throw new IllegalArgumentException("Session input buffer may not be null");
    }
    if (parser == null)
        parser = BasicLineParser.DEFAULT;
    ArrayList headerLines = new ArrayList();
    CharArrayBuffer current = null;
    CharArrayBuffer previous = null;
    for (; ; ) {
        if (current == null) {
            current = new CharArrayBuffer(64);
        } else {
            current.clear();
        }
        int l = inbuffer.readLine(current);
        if (l == -1 || current.length() < 1) {
            break;
        }
        // discussion on folded headers
        if ((current.charAt(0) == ' ' || current.charAt(0) == '\t') && previous != null) {
            // we have continuation folded header
            // so append value
            int i = 0;
            while (i < current.length()) {
                char ch = current.charAt(i);
                if (ch != ' ' && ch != '\t') {
                    break;
                }
                i++;
            }
            if (maxLineLen > 0 && 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);
            previous = current;
            current = null;
        }
        if (maxHeaderCount > 0 && headerLines.size() >= maxHeaderCount) {
            throw new IOException("Maximum header count exceeded");
        }
    }
    Header[] headers = new Header[headerLines.size()];
    for (int i = 0; i < headerLines.size(); i++) {
        CharArrayBuffer buffer = (CharArrayBuffer) headerLines.get(i);
        try {
            headers[i] = parser.parseHeader(buffer);
        } catch (ParseException ex) {
            throw new ProtocolException(ex.getMessage());
        }
    }
    return headers;
}
Also used : ProtocolException(org.apache.http.ProtocolException) Header(org.apache.http.Header) ArrayList(java.util.ArrayList) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) IOException(java.io.IOException) ParseException(org.apache.http.ParseException)

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