Android Open Source - volley Headers






From Project

Back to project page volley.

License

The source code is released under:

MIT License

If you think the Android project volley listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gm.android.volley;
//from  w  ww .j a v  a 2s  . c  om
import com.android.volley.VolleyLog;

import org.apache.http.Header;
import org.apache.http.HeaderElement;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Pattern;

public enum Headers {
    //According to RFC2617
    WWWAuthenticate("WWW-Authenticate", new String[]{"realm", "nonce", "opaque", "stale", "algorithm", "qop", "domain"}),
    Authorization(new String[]{"realm", "nonce", "opaque", "stale", "algorithm", "qop", "username", "uri", "cnonce", "nc", "response"}),
    AuthenticationInfo("Authentication-Info", new String[]{"qop", "nc", "digest", "nextnonce", "rspauth"});

    private String val;
    private String[] vals;
    private Pattern regex;

    private Headers(String[] headerValues) {
        init(this.name(), headerValues);
    }

    private Headers(String val, String[] headerValues) {
        init(val, headerValues);
    }

    private void init(String val, String[] headerValues) {
        this.val = val;
        if (headerValues == null) {
            this.vals = new String[0];
            this.regex = Pattern.compile("");
        } else {
            this.vals = headerValues == null ? new String[0] : headerValues;
            this.regex = initPattern(this.vals);
        }
    }

    private Pattern initPattern(String[] vals) {
        String concat = "";
        for (String v : vals) {
            if (concat.isEmpty())
                concat += val;
            else concat += "|" + val;
        }
        return Pattern.compile("(" + concat + ")=(\"?(\\w+)\"?)");
    }

    public String val() {
        return this.val;
    }

    public String[] headerValues() {
        return this.vals;
    }

    public Map<String, String> toMap(Header headerValue) {
        LinkedHashMap<String, String> header = new LinkedHashMap<String,String>(this.vals.length);
        for (HeaderElement he : headerValue.getElements()) {
            for (String val : this.vals) {
                if (he.getName().contains(val))
                    header.put(val, he.getValue());
            }
        }
        VolleyLog.d("Authorization values: %s", header);
        return header;
    }

    public String make(Map<String, String> values) {
        String value = "Digest ";
        boolean comma = false;
        for (String val : this.vals) {
            String hv = values.get(val);
            if (hv != null) {
                if (comma) value += ", ";
                else comma = true;
                value += val + "=";
                if ("nc".equals(val) || "qop".equals(val)) {
                    value += hv;
                } else {
                    value += "\"" + hv + "\"";
                }
            }
        }
        VolleyLog.d("%s header: %s", this.val, value);
        return value;
    }
}




Java Source Code List

com.android.volley.AuthFailureError.java
com.android.volley.CacheDispatcher.java
com.android.volley.Cache.java
com.android.volley.DefaultRetryPolicy.java
com.android.volley.ExecutorDelivery.java
com.android.volley.NetworkDispatcher.java
com.android.volley.NetworkError.java
com.android.volley.NetworkResponse.java
com.android.volley.Network.java
com.android.volley.NoConnectionError.java
com.android.volley.ParseError.java
com.android.volley.RequestQueue.java
com.android.volley.Request.java
com.android.volley.ResponseDelivery.java
com.android.volley.Response.java
com.android.volley.RetryPolicy.java
com.android.volley.ServerError.java
com.android.volley.TimeoutError.java
com.android.volley.VolleyError.java
com.android.volley.VolleyLog.java
com.android.volley.toolbox.AndroidAuthenticator.java
com.android.volley.toolbox.Authenticator.java
com.android.volley.toolbox.BasicNetwork.java
com.android.volley.toolbox.ByteArrayPool.java
com.android.volley.toolbox.ClearCacheRequest.java
com.android.volley.toolbox.DiskBasedCache.java
com.android.volley.toolbox.HttpClientStack.java
com.android.volley.toolbox.HttpHeaderParser.java
com.android.volley.toolbox.HttpStack.java
com.android.volley.toolbox.HurlStack.java
com.android.volley.toolbox.ImageLoader.java
com.android.volley.toolbox.ImageRequest.java
com.android.volley.toolbox.JsonArrayRequest.java
com.android.volley.toolbox.JsonObjectRequest.java
com.android.volley.toolbox.JsonRequest.java
com.android.volley.toolbox.NetworkImageView.java
com.android.volley.toolbox.NoCache.java
com.android.volley.toolbox.PoolingByteArrayOutputStream.java
com.android.volley.toolbox.RequestFuture.java
com.android.volley.toolbox.StringRequest.java
com.android.volley.toolbox.Volley.java
com.gm.android.volley.Headers.java
com.gm.android.volley.HttpDigestStack.java
com.gm.android.volley.jackson.JacksonRequest.java