FileDocCategorySizeDatePackage
Headers.javaAPI DocAndroid 5.1 API15893Thu Mar 12 22:22:10 GMT 2015android.net.http

Headers

public final class Headers extends Object
Manages received headers {@hide}

Fields Summary
private static final String
LOGTAG
public static final int
CONN_CLOSE
indicate HTTP 1.0 connection close after the response
public static final int
CONN_KEEP_ALIVE
indicate HTTP 1.1 connection keep alive
public static final int
NO_CONN_TYPE
public static final long
NO_TRANSFER_ENCODING
public static final long
NO_CONTENT_LENGTH
public static final String
TRANSFER_ENCODING
public static final String
CONTENT_LEN
public static final String
CONTENT_TYPE
public static final String
CONTENT_ENCODING
public static final String
CONN_DIRECTIVE
public static final String
LOCATION
public static final String
PROXY_CONNECTION
public static final String
WWW_AUTHENTICATE
public static final String
PROXY_AUTHENTICATE
public static final String
CONTENT_DISPOSITION
public static final String
ACCEPT_RANGES
public static final String
EXPIRES
public static final String
CACHE_CONTROL
public static final String
LAST_MODIFIED
public static final String
ETAG
public static final String
SET_COOKIE
public static final String
PRAGMA
public static final String
REFRESH
public static final String
X_PERMITTED_CROSS_DOMAIN_POLICIES
private static final int
HASH_TRANSFER_ENCODING
private static final int
HASH_CONTENT_LEN
private static final int
HASH_CONTENT_TYPE
private static final int
HASH_CONTENT_ENCODING
private static final int
HASH_CONN_DIRECTIVE
private static final int
HASH_LOCATION
private static final int
HASH_PROXY_CONNECTION
private static final int
HASH_WWW_AUTHENTICATE
private static final int
HASH_PROXY_AUTHENTICATE
private static final int
HASH_CONTENT_DISPOSITION
private static final int
HASH_ACCEPT_RANGES
private static final int
HASH_EXPIRES
private static final int
HASH_CACHE_CONTROL
private static final int
HASH_LAST_MODIFIED
private static final int
HASH_ETAG
private static final int
HASH_SET_COOKIE
private static final int
HASH_PRAGMA
private static final int
HASH_REFRESH
private static final int
HASH_X_PERMITTED_CROSS_DOMAIN_POLICIES
private static final int
IDX_TRANSFER_ENCODING
private static final int
IDX_CONTENT_LEN
private static final int
IDX_CONTENT_TYPE
private static final int
IDX_CONTENT_ENCODING
private static final int
IDX_CONN_DIRECTIVE
private static final int
IDX_LOCATION
private static final int
IDX_PROXY_CONNECTION
private static final int
IDX_WWW_AUTHENTICATE
private static final int
IDX_PROXY_AUTHENTICATE
private static final int
IDX_CONTENT_DISPOSITION
private static final int
IDX_ACCEPT_RANGES
private static final int
IDX_EXPIRES
private static final int
IDX_CACHE_CONTROL
private static final int
IDX_LAST_MODIFIED
private static final int
IDX_ETAG
private static final int
IDX_SET_COOKIE
private static final int
IDX_PRAGMA
private static final int
IDX_REFRESH
private static final int
IDX_X_PERMITTED_CROSS_DOMAIN_POLICIES
private static final int
HEADER_COUNT
private long
transferEncoding
private long
contentLength
private int
connectionType
private ArrayList
cookies
private String[]
mHeaders
private static final String[]
sHeaderNames
private ArrayList
mExtraHeaderNames
private ArrayList
mExtraHeaderValues
Constructors Summary
public Headers()


      
        transferEncoding = NO_TRANSFER_ENCODING;
        contentLength = NO_CONTENT_LENGTH;
        connectionType = NO_CONN_TYPE;
    
Methods Summary
public java.lang.StringgetAcceptRanges()

        return mHeaders[IDX_ACCEPT_RANGES];
    
public java.lang.StringgetCacheControl()

        return mHeaders[IDX_CACHE_CONTROL];
    
public intgetConnectionType()

        return connectionType;
    
public java.lang.StringgetContentDisposition()

        return mHeaders[IDX_CONTENT_DISPOSITION];
    
public java.lang.StringgetContentEncoding()

        return mHeaders[IDX_CONTENT_ENCODING];
    
public longgetContentLength()

        return contentLength;
    
public java.lang.StringgetContentType()

        return mHeaders[IDX_CONTENT_TYPE];
    
public java.lang.StringgetEtag()

        return mHeaders[IDX_ETAG];
    
public java.lang.StringgetExpires()

        return mHeaders[IDX_EXPIRES];
    
public voidgetHeaders(android.net.http.Headers$HeaderCallback hcb)
Reports all non-null headers to the callback

        for (int i = 0; i < HEADER_COUNT; i++) {
            String h = mHeaders[i];
            if (h != null) {
                hcb.header(sHeaderNames[i], h);
            }
        }
        int extraLen = mExtraHeaderNames.size();
        for (int i = 0; i < extraLen; i++) {
            if (false) {
                HttpLog.v("Headers.getHeaders() extra: " + i + " " +
                          mExtraHeaderNames.get(i) + " " + mExtraHeaderValues.get(i));
            }
            hcb.header(mExtraHeaderNames.get(i),
                       mExtraHeaderValues.get(i));
        }

    
public java.lang.StringgetLastModified()

        return mHeaders[IDX_LAST_MODIFIED];
    
public java.lang.StringgetLocation()

        return mHeaders[IDX_LOCATION];
    
public java.lang.StringgetPragma()

        return mHeaders[IDX_PRAGMA];
    
public java.lang.StringgetProxyAuthenticate()

        return mHeaders[IDX_PROXY_AUTHENTICATE];
    
public java.lang.StringgetRefresh()

        return mHeaders[IDX_REFRESH];
    
public java.util.ArrayListgetSetCookie()

        return this.cookies;
    
public longgetTransferEncoding()

        return transferEncoding;
    
public java.lang.StringgetWwwAuthenticate()

        return mHeaders[IDX_WWW_AUTHENTICATE];
    
public java.lang.StringgetXPermittedCrossDomainPolicies()

        return mHeaders[IDX_X_PERMITTED_CROSS_DOMAIN_POLICIES];
    
public voidparseHeader(org.apache.http.util.CharArrayBuffer buffer)

        int pos = CharArrayBuffers.setLowercaseIndexOf(buffer, ':");
        if (pos == -1) {
            return;
        }
        String name = buffer.substringTrimmed(0, pos);
        if (name.length() == 0) {
            return;
        }
        pos++;

        String val = buffer.substringTrimmed(pos, buffer.length());
        if (HttpLog.LOGV) {
            HttpLog.v("hdr " + buffer.length() + " " + buffer);
        }

        switch (name.hashCode()) {
        case HASH_TRANSFER_ENCODING:
            if (name.equals(TRANSFER_ENCODING)) {
                mHeaders[IDX_TRANSFER_ENCODING] = val;
                HeaderElement[] encodings = BasicHeaderValueParser.DEFAULT
                        .parseElements(buffer, new ParserCursor(pos,
                                buffer.length()));
                // The chunked encoding must be the last one applied RFC2616,
                // 14.41
                int len = encodings.length;
                if (HTTP.IDENTITY_CODING.equalsIgnoreCase(val)) {
                    transferEncoding = ContentLengthStrategy.IDENTITY;
                } else if ((len > 0)
                        && (HTTP.CHUNK_CODING
                                .equalsIgnoreCase(encodings[len - 1].getName()))) {
                    transferEncoding = ContentLengthStrategy.CHUNKED;
                } else {
                    transferEncoding = ContentLengthStrategy.IDENTITY;
                }
            }
            break;
        case HASH_CONTENT_LEN:
            if (name.equals(CONTENT_LEN)) {
                mHeaders[IDX_CONTENT_LEN] = val;
                try {
                    contentLength = Long.parseLong(val);
                } catch (NumberFormatException e) {
                    if (false) {
                        Log.v(LOGTAG, "Headers.headers(): error parsing"
                                + " content length: " + buffer.toString());
                    }
                }
            }
            break;
        case HASH_CONTENT_TYPE:
            if (name.equals(CONTENT_TYPE)) {
                mHeaders[IDX_CONTENT_TYPE] = val;
            }
            break;
        case HASH_CONTENT_ENCODING:
            if (name.equals(CONTENT_ENCODING)) {
                mHeaders[IDX_CONTENT_ENCODING] = val;
            }
            break;
        case HASH_CONN_DIRECTIVE:
            if (name.equals(CONN_DIRECTIVE)) {
                mHeaders[IDX_CONN_DIRECTIVE] = val;
                setConnectionType(buffer, pos);
            }
            break;
        case HASH_LOCATION:
            if (name.equals(LOCATION)) {
                mHeaders[IDX_LOCATION] = val;
            }
            break;
        case HASH_PROXY_CONNECTION:
            if (name.equals(PROXY_CONNECTION)) {
                mHeaders[IDX_PROXY_CONNECTION] = val;
                setConnectionType(buffer, pos);
            }
            break;
        case HASH_WWW_AUTHENTICATE:
            if (name.equals(WWW_AUTHENTICATE)) {
                mHeaders[IDX_WWW_AUTHENTICATE] = val;
            }
            break;
        case HASH_PROXY_AUTHENTICATE:
            if (name.equals(PROXY_AUTHENTICATE)) {
                mHeaders[IDX_PROXY_AUTHENTICATE] = val;
            }
            break;
        case HASH_CONTENT_DISPOSITION:
            if (name.equals(CONTENT_DISPOSITION)) {
                mHeaders[IDX_CONTENT_DISPOSITION] = val;
            }
            break;
        case HASH_ACCEPT_RANGES:
            if (name.equals(ACCEPT_RANGES)) {
                mHeaders[IDX_ACCEPT_RANGES] = val;
            }
            break;
        case HASH_EXPIRES:
            if (name.equals(EXPIRES)) {
                mHeaders[IDX_EXPIRES] = val;
            }
            break;
        case HASH_CACHE_CONTROL:
            if (name.equals(CACHE_CONTROL)) {
                // In case where we receive more than one header, create a ',' separated list.
                // This should be ok, according to RFC 2616 chapter 4.2
                if (mHeaders[IDX_CACHE_CONTROL] != null &&
                    mHeaders[IDX_CACHE_CONTROL].length() > 0) {
                    mHeaders[IDX_CACHE_CONTROL] += ('," + val);
                } else {
                    mHeaders[IDX_CACHE_CONTROL] = val;
                }
            }
            break;
        case HASH_LAST_MODIFIED:
            if (name.equals(LAST_MODIFIED)) {
                mHeaders[IDX_LAST_MODIFIED] = val;
            }
            break;
        case HASH_ETAG:
            if (name.equals(ETAG)) {
                mHeaders[IDX_ETAG] = val;
            }
            break;
        case HASH_SET_COOKIE:
            if (name.equals(SET_COOKIE)) {
                mHeaders[IDX_SET_COOKIE] = val;
                cookies.add(val);
            }
            break;
        case HASH_PRAGMA:
            if (name.equals(PRAGMA)) {
                mHeaders[IDX_PRAGMA] = val;
            }
            break;
        case HASH_REFRESH:
            if (name.equals(REFRESH)) {
                mHeaders[IDX_REFRESH] = val;
            }
            break;
        case HASH_X_PERMITTED_CROSS_DOMAIN_POLICIES:
            if (name.equals(X_PERMITTED_CROSS_DOMAIN_POLICIES)) {
                mHeaders[IDX_X_PERMITTED_CROSS_DOMAIN_POLICIES] = val;
            }
            break;
        default:
            mExtraHeaderNames.add(name);
            mExtraHeaderValues.add(val);
        }
    
public voidsetAcceptRanges(java.lang.String value)

        mHeaders[IDX_ACCEPT_RANGES] = value;
    
public voidsetCacheControl(java.lang.String value)

        mHeaders[IDX_CACHE_CONTROL] = value;
    
private voidsetConnectionType(org.apache.http.util.CharArrayBuffer buffer, int pos)

        if (CharArrayBuffers.containsIgnoreCaseTrimmed(
                buffer, pos, HTTP.CONN_CLOSE)) {
            connectionType = CONN_CLOSE;
        } else if (CharArrayBuffers.containsIgnoreCaseTrimmed(
                buffer, pos, HTTP.CONN_KEEP_ALIVE)) {
            connectionType = CONN_KEEP_ALIVE;
        }
    
public voidsetContentDisposition(java.lang.String value)

        mHeaders[IDX_CONTENT_DISPOSITION] = value;
    
public voidsetContentEncoding(java.lang.String value)

        mHeaders[IDX_CONTENT_ENCODING] = value;
    
public voidsetContentLength(long value)

        this.contentLength = value;
    
public voidsetContentType(java.lang.String value)

        mHeaders[IDX_CONTENT_TYPE] = value;
    
public voidsetEtag(java.lang.String value)

        mHeaders[IDX_ETAG] = value;
    
public voidsetExpires(java.lang.String value)

        mHeaders[IDX_EXPIRES] = value;
    
public voidsetLastModified(java.lang.String value)

        mHeaders[IDX_LAST_MODIFIED] = value;
    
public voidsetLocation(java.lang.String value)

        mHeaders[IDX_LOCATION] = value;
    
public voidsetProxyAuthenticate(java.lang.String value)

        mHeaders[IDX_PROXY_AUTHENTICATE] = value;
    
public voidsetWwwAuthenticate(java.lang.String value)

        mHeaders[IDX_WWW_AUTHENTICATE] = value;
    
public voidsetXPermittedCrossDomainPolicies(java.lang.String value)

        mHeaders[IDX_X_PERMITTED_CROSS_DOMAIN_POLICIES] = value;