Search in sources :

Example 11 with FormattedHeader

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

the class BasicHeaderElementIterator method bufferHeaderValue.

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

Example 12 with FormattedHeader

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

the class BasicLineFormatter method formatHeader.

// non-javadoc, see interface LineFormatter
public CharArrayBuffer formatHeader(CharArrayBuffer buffer, Header header) {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    CharArrayBuffer result = null;
    if (header instanceof FormattedHeader) {
        // If the header is backed by a buffer, re-use the buffer
        result = ((FormattedHeader) header).getBuffer();
    } else {
        result = initBuffer(buffer);
        doFormatHeader(result, header);
    }
    return result;
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer) FormattedHeader(org.apache.http.FormattedHeader)

Example 13 with FormattedHeader

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

the class AbstractAuthenticationHandler method parseChallenges.

protected Map<String, Header> parseChallenges(final Header[] headers) throws MalformedChallengeException {
    Map<String, Header> map = new HashMap<String, Header>(headers.length);
    for (Header header : headers) {
        CharArrayBuffer 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++;
        }
        int beginIndex = pos;
        while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int endIndex = pos;
        String s = buffer.substring(beginIndex, endIndex);
        map.put(s.toLowerCase(Locale.ENGLISH), header);
    }
    return map;
}
Also used : Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) HashMap(java.util.HashMap) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) FormattedHeader(org.apache.http.FormattedHeader)

Example 14 with FormattedHeader

use of org.apache.http.FormattedHeader in project robovm by robovm.

the class BasicHeaderElementIterator method bufferHeaderValue.

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

Example 15 with FormattedHeader

use of org.apache.http.FormattedHeader in project robovm by robovm.

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

FormattedHeader (org.apache.http.FormattedHeader)18 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)18 Header (org.apache.http.Header)6 MalformedChallengeException (org.apache.http.auth.MalformedChallengeException)6 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)6 ParserCursor (org.apache.http.message.ParserCursor)6 HashMap (java.util.HashMap)3 HeaderElement (org.apache.http.HeaderElement)3