Search in sources :

Example 26 with ParserCursor

use of org.apache.http.message.ParserCursor in project platform_external_apache-http by android.

the class BrowserCompatSpec method parse.

public List<Cookie> parse(final Header header, final CookieOrigin origin) throws MalformedCookieException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    String headervalue = header.getValue();
    boolean isNetscapeCookie = false;
    int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires=");
    if (i1 != -1) {
        i1 += "expires=".length();
        int i2 = headervalue.indexOf(';', i1);
        if (i2 == -1) {
            i2 = headervalue.length();
        }
        try {
            DateUtils.parseDate(headervalue.substring(i1, i2), this.datepatterns);
            isNetscapeCookie = true;
        } catch (DateParseException e) {
        // Does not look like a valid expiry date
        }
    }
    HeaderElement[] elems = null;
    if (isNetscapeCookie) {
        NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
        CharArrayBuffer buffer;
        ParserCursor cursor;
        if (header instanceof FormattedHeader) {
            buffer = ((FormattedHeader) header).getBuffer();
            cursor = new ParserCursor(((FormattedHeader) header).getValuePos(), buffer.length());
        } else {
            String s = header.getValue();
            if (s == null) {
                throw new MalformedCookieException("Header value is null");
            }
            buffer = new CharArrayBuffer(s.length());
            buffer.append(s);
            cursor = new ParserCursor(0, buffer.length());
        }
        elems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
    } else {
        elems = header.getElements();
    }
    return parse(elems, origin);
}
Also used : ParserCursor(org.apache.http.message.ParserCursor) HeaderElement(org.apache.http.HeaderElement) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) FormattedHeader(org.apache.http.FormattedHeader)

Aggregations

ParserCursor (org.apache.http.message.ParserCursor)26 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)11 HeaderElement (org.apache.http.HeaderElement)9 NoHttpResponseException (org.apache.http.NoHttpResponseException)9 StatusLine (org.apache.http.StatusLine)9 FormattedHeader (org.apache.http.FormattedHeader)6 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)6 BasicHeaderValueParser (org.apache.http.message.BasicHeaderValueParser)5 IOException (java.io.IOException)3 ConnectionClosedException (org.apache.http.ConnectionClosedException)3 ProtocolException (org.apache.http.ProtocolException)3 RequestLine (org.apache.http.RequestLine)3 MalformedChallengeException (org.apache.http.auth.MalformedChallengeException)3 HeaderValueParser (org.apache.http.message.HeaderValueParser)3 NameValuePair (org.apache.http.NameValuePair)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 ArrayList (java.util.ArrayList)1