@@ -138,7 +138,7 @@ public void process(HttpRequest request, HttpContext context) {
138
138
request .addHeader (HEADER_ACCEPT_ENCODING , ENCODING_GZIP );
139
139
}
140
140
for (String header : clientHeaderMap .keySet ()) {
141
- request .addHeader (header , clientHeaderMap .get (header ));
141
+ request .addHeader (header , clientHeaderMap .get (header ));
142
142
}
143
143
}
144
144
});
@@ -239,7 +239,31 @@ public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
239
239
* @param value the contents of the header
240
240
*/
241
241
public void addHeader (String header , String value ) {
242
- clientHeaderMap .put (header , value );
242
+ clientHeaderMap .put (header , value );
243
+ }
244
+
245
+ /**
246
+ * Sets basic authentication for the request. Uses AuthScope.ANY. This is the same as
247
+ * setBasicAuth('username','password',AuthScope.ANY)
248
+ * @param username
249
+ * @param password
250
+ */
251
+ public void setBasicAuth (String user , String pass ){
252
+ AuthScope scope = AuthScope .ANY ;
253
+ setBasicAuth (user , pass , scope );
254
+ }
255
+
256
+ /**
257
+ * Sets basic authentication for the request. You should pass in your AuthScope for security. It should be like this
258
+ * setBasicAuth("username","password", new AuthScope("host",port,AuthScope.ANY_REALM))
259
+ * @param username
260
+ * @param password
261
+ * @param scope - an AuthScope object
262
+ *
263
+ */
264
+ public void setBasicAuth ( String user , String pass , AuthScope scope ){
265
+ UsernamePasswordCredentials credentials = new UsernamePasswordCredentials (user ,pass );
266
+ this .httpClient .getCredentialsProvider ().setCredentials (scope , credentials );
243
267
}
244
268
245
269
/**
0 commit comments