20
20
21
21
import java .io .IOException ;
22
22
import java .io .InputStream ;
23
- import java .util .List ;
23
+ import java .lang .ref .WeakReference ;
24
+ import java .util .HashMap ;
24
25
import java .util .LinkedList ;
26
+ import java .util .List ;
25
27
import java .util .Map ;
26
28
import java .util .WeakHashMap ;
27
- import java .lang .ref .WeakReference ;
28
29
import java .util .concurrent .Executors ;
29
30
import java .util .concurrent .Future ;
30
31
import java .util .concurrent .ThreadPoolExecutor ;
40
41
import org .apache .http .HttpVersion ;
41
42
import org .apache .http .client .CookieStore ;
42
43
import org .apache .http .client .HttpClient ;
44
+ import org .apache .http .client .methods .HttpDelete ;
45
+ import org .apache .http .client .methods .HttpEntityEnclosingRequestBase ;
43
46
import org .apache .http .client .methods .HttpGet ;
44
47
import org .apache .http .client .methods .HttpPost ;
45
48
import org .apache .http .client .methods .HttpPut ;
46
- import org .apache .http .client .methods .HttpDelete ;
47
- import org .apache .http .client .methods .HttpRequestBase ;
48
49
import org .apache .http .client .methods .HttpUriRequest ;
49
- import org .apache .http .client .methods .HttpEntityEnclosingRequestBase ;
50
50
import org .apache .http .client .protocol .ClientContext ;
51
51
import org .apache .http .conn .params .ConnManagerParams ;
52
52
import org .apache .http .conn .params .ConnPerRouteBean ;
61
61
import org .apache .http .params .HttpConnectionParams ;
62
62
import org .apache .http .params .HttpProtocolParams ;
63
63
import org .apache .http .protocol .BasicHttpContext ;
64
- import org .apache .http .protocol .SyncBasicHttpContext ;
65
64
import org .apache .http .protocol .HttpContext ;
65
+ import org .apache .http .protocol .SyncBasicHttpContext ;
66
66
67
67
import android .content .Context ;
68
68
@@ -103,6 +103,7 @@ public class AsyncHttpClient {
103
103
private HttpContext httpContext ;
104
104
private ThreadPoolExecutor threadPool ;
105
105
private Map <Context , List <WeakReference <Future >>> requestMap ;
106
+ private Map <String , String >headerMap ;
106
107
107
108
108
109
/**
@@ -133,6 +134,9 @@ public void process(HttpRequest request, HttpContext context) {
133
134
if (!request .containsHeader (HEADER_ACCEPT_ENCODING )) {
134
135
request .addHeader (HEADER_ACCEPT_ENCODING , ENCODING_GZIP );
135
136
}
137
+ for (String header : headerMap .keySet ()) {
138
+ request .addHeader (header , headerMap .get (header ));
139
+ }
136
140
}
137
141
});
138
142
@@ -156,6 +160,7 @@ public void process(HttpResponse response, HttpContext context) {
156
160
threadPool = (ThreadPoolExecutor )Executors .newCachedThreadPool ();
157
161
158
162
requestMap = new WeakHashMap <Context , List <WeakReference <Future >>>();
163
+ headerMap = new HashMap <String , String >();
159
164
}
160
165
161
166
/**
@@ -201,6 +206,13 @@ public void setUserAgent(String userAgent) {
201
206
public void setSSLSocketFactory (SSLSocketFactory sslSocketFactory ) {
202
207
this .httpClient .getConnectionManager ().getSchemeRegistry ().register (new Scheme ("https" , sslSocketFactory , 443 ));
203
208
}
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
+ }
204
216
205
217
/**
206
218
* Cancels any pending (or potentially active) requests associated with the
0 commit comments