2020
2121import java .io .IOException ;
2222import java .io .InputStream ;
23- import java .util .List ;
23+ import java .lang .ref .WeakReference ;
24+ import java .util .HashMap ;
2425import java .util .LinkedList ;
26+ import java .util .List ;
2527import java .util .Map ;
2628import java .util .WeakHashMap ;
27- import java .lang .ref .WeakReference ;
2829import java .util .concurrent .Executors ;
2930import java .util .concurrent .Future ;
3031import java .util .concurrent .ThreadPoolExecutor ;
4041import org .apache .http .HttpVersion ;
4142import org .apache .http .client .CookieStore ;
4243import org .apache .http .client .HttpClient ;
44+ import org .apache .http .client .methods .HttpDelete ;
45+ import org .apache .http .client .methods .HttpEntityEnclosingRequestBase ;
4346import org .apache .http .client .methods .HttpGet ;
4447import org .apache .http .client .methods .HttpPost ;
4548import org .apache .http .client .methods .HttpPut ;
46- import org .apache .http .client .methods .HttpDelete ;
47- import org .apache .http .client .methods .HttpRequestBase ;
4849import org .apache .http .client .methods .HttpUriRequest ;
49- import org .apache .http .client .methods .HttpEntityEnclosingRequestBase ;
5050import org .apache .http .client .protocol .ClientContext ;
5151import org .apache .http .conn .params .ConnManagerParams ;
5252import org .apache .http .conn .params .ConnPerRouteBean ;
6161import org .apache .http .params .HttpConnectionParams ;
6262import org .apache .http .params .HttpProtocolParams ;
6363import org .apache .http .protocol .BasicHttpContext ;
64- import org .apache .http .protocol .SyncBasicHttpContext ;
6564import org .apache .http .protocol .HttpContext ;
65+ import org .apache .http .protocol .SyncBasicHttpContext ;
6666
6767import android .content .Context ;
6868
@@ -103,6 +103,7 @@ public class AsyncHttpClient {
103103 private HttpContext httpContext ;
104104 private ThreadPoolExecutor threadPool ;
105105 private Map <Context , List <WeakReference <Future >>> requestMap ;
106+ private Map <String , String >headerMap ;
106107
107108
108109 /**
@@ -133,6 +134,9 @@ public void process(HttpRequest request, HttpContext context) {
133134 if (!request .containsHeader (HEADER_ACCEPT_ENCODING )) {
134135 request .addHeader (HEADER_ACCEPT_ENCODING , ENCODING_GZIP );
135136 }
137+ for (String header : headerMap .keySet ()) {
138+ request .addHeader (header , headerMap .get (header ));
139+ }
136140 }
137141 });
138142
@@ -156,6 +160,7 @@ public void process(HttpResponse response, HttpContext context) {
156160 threadPool = (ThreadPoolExecutor )Executors .newCachedThreadPool ();
157161
158162 requestMap = new WeakHashMap <Context , List <WeakReference <Future >>>();
163+ headerMap = new HashMap <String , String >();
159164 }
160165
161166 /**
@@ -201,6 +206,13 @@ public void setUserAgent(String userAgent) {
201206 public void setSSLSocketFactory (SSLSocketFactory sslSocketFactory ) {
202207 this .httpClient .getConnectionManager ().getSchemeRegistry ().register (new Scheme ("https" , sslSocketFactory , 443 ));
203208 }
209+
210+ /**
211+ * Sets headers that will get added when the request is intercepted (before sending).
212+ */
213+ public void addHeader (String header , String value ) {
214+ headerMap .put (header , value );
215+ }
204216
205217 /**
206218 * Cancels any pending (or potentially active) requests associated with the
0 commit comments