13
13
*/
14
14
package org .asynchttpclient .netty .request ;
15
15
16
- import static org .asynchttpclient .ntlm . NtlmUtils . getNTLM ;
17
- import static org .asynchttpclient .util .AsyncHttpProviderUtils .* ;
18
- import static org .asynchttpclient .util .AuthenticatorUtils . computeBasicAuthentication ;
19
- import static org .asynchttpclient .util .AuthenticatorUtils . computeDigestAuthentication ;
16
+ import static org .asynchttpclient .util . AsyncHttpProviderUtils . DEFAULT_CHARSET ;
17
+ import static org .asynchttpclient .util .AsyncHttpProviderUtils .hostHeader ;
18
+ import static org .asynchttpclient .util .AsyncHttpProviderUtils . keepAliveHeaderValue ;
19
+ import static org .asynchttpclient .util .AsyncHttpProviderUtils . urlEncodeFormParams ;
20
20
import static org .asynchttpclient .util .HttpUtils .isSecure ;
21
21
import static org .asynchttpclient .util .HttpUtils .isWebSocket ;
22
- import static org .asynchttpclient .util .HttpUtils .useProxyConnect ;
23
22
import static org .asynchttpclient .util .MiscUtils .isNonEmpty ;
24
23
import static org .asynchttpclient .ws .WebSocketUtils .getKey ;
25
24
30
29
31
30
import org .asynchttpclient .AsyncHttpClientConfig ;
32
31
import org .asynchttpclient .Realm ;
33
- import org .asynchttpclient .Realm .AuthScheme ;
34
32
import org .asynchttpclient .Request ;
35
33
import org .asynchttpclient .cookie .CookieEncoder ;
36
34
import org .asynchttpclient .netty .request .body .NettyBody ;
42
40
import org .asynchttpclient .netty .request .body .NettyFileBody ;
43
41
import org .asynchttpclient .netty .request .body .NettyInputStreamBody ;
44
42
import org .asynchttpclient .netty .request .body .NettyMultipartBody ;
45
- import org .asynchttpclient .ntlm .NtlmEngine ;
46
43
import org .asynchttpclient .proxy .ProxyServer ;
47
44
import org .asynchttpclient .request .body .generator .FileBodyGenerator ;
48
45
import org .asynchttpclient .request .body .generator .InputStreamBodyGenerator ;
@@ -63,77 +60,13 @@ public NettyRequestFactory(AsyncHttpClientConfig config) {
63
60
super (config );
64
61
}
65
62
66
- private String requestUri (Uri uri , ProxyServer proxyServer , HttpMethod method ) {
67
- if (method == HttpMethod .CONNECT )
68
- return getAuthority (uri );
69
-
70
- else if (proxyServer != null && !useProxyConnect (uri ))
71
- return uri .toUrl ();
72
-
73
- else {
74
- String path = getNonEmptyPath (uri );
75
- if (isNonEmpty (uri .getQuery ()))
76
- return path + "?" + uri .getQuery ();
77
- else
78
- return path ;
79
- }
80
- }
81
-
82
- public String firstRequestOnlyProxyAuthorizationHeader (Request request , ProxyServer proxyServer , HttpMethod method ) throws IOException {
83
- String proxyAuthorization = null ;
84
-
85
- if (method == HttpMethod .CONNECT ) {
86
- List <String > auth = request .getHeaders ().get (HttpHeaders .Names .PROXY_AUTHORIZATION );
87
- String ntlmHeader = getNTLM (auth );
88
- if (ntlmHeader != null ) {
89
- proxyAuthorization = ntlmHeader ;
90
- }
91
-
92
- } else if (proxyServer != null && proxyServer .getPrincipal () != null && isNonEmpty (proxyServer .getNtlmDomain ())) {
93
- List <String > auth = request .getHeaders ().get (HttpHeaders .Names .PROXY_AUTHORIZATION );
94
- if (getNTLM (auth ) == null ) {
95
- String msg = NtlmEngine .INSTANCE .generateType1Msg ();
96
- proxyAuthorization = "NTLM " + msg ;
97
- }
98
- }
99
-
100
- return proxyAuthorization ;
63
+ protected List <String > getProxyAuthorizationHeader (Request request ) {
64
+ return request .getHeaders ().get (HttpHeaders .Names .PROXY_AUTHORIZATION );
101
65
}
102
66
103
- private String systematicProxyAuthorizationHeader (Request request , ProxyServer proxyServer , Realm realm , HttpMethod method ) {
104
-
105
- String proxyAuthorization = null ;
106
-
107
- if (method != HttpMethod .CONNECT && proxyServer != null && proxyServer .getPrincipal () != null && proxyServer .getScheme () == AuthScheme .BASIC ) {
108
- proxyAuthorization = computeBasicAuthentication (proxyServer );
109
-
110
- } else if (realm != null && realm .getUsePreemptiveAuth () && realm .isTargetProxy ()) {
111
-
112
- switch (realm .getScheme ()) {
113
- case BASIC :
114
- proxyAuthorization = computeBasicAuthentication (realm );
115
- break ;
116
- case DIGEST :
117
- if (isNonEmpty (realm .getNonce ()))
118
- proxyAuthorization = computeDigestAuthentication (realm );
119
- break ;
120
- case NTLM :
121
- case KERBEROS :
122
- case SPNEGO :
123
- // NTLM, KERBEROS and SPNEGO are only set on the first request, see firstRequestOnlyAuthorizationHeader
124
- case NONE :
125
- break ;
126
- default :
127
- throw new IllegalStateException ("Invalid Authentication " + realm );
128
- }
129
- }
130
-
131
- return proxyAuthorization ;
132
- }
133
-
134
- private NettyBody body (Request request , HttpMethod method ) throws IOException {
67
+ private NettyBody body (Request request , boolean connect ) throws IOException {
135
68
NettyBody nettyBody = null ;
136
- if (method != HttpMethod . CONNECT ) {
69
+ if (! connect ) {
137
70
138
71
Charset bodyCharset = request .getBodyCharset () == null ? DEFAULT_CHARSET : request .getBodyCharset ();
139
72
@@ -193,10 +126,12 @@ public NettyRequest newNettyRequest(Request request, Uri uri, boolean forceConne
193
126
throws IOException {
194
127
195
128
HttpMethod method = forceConnect ? HttpMethod .CONNECT : HttpMethod .valueOf (request .getMethod ());
196
- HttpVersion httpVersion = method == HttpMethod .CONNECT && proxyServer .isForceHttp10 () ? HttpVersion .HTTP_1_0 : HttpVersion .HTTP_1_1 ;
197
- String requestUri = requestUri (uri , proxyServer , method );
129
+ boolean connect = method == HttpMethod .CONNECT ;
130
+
131
+ HttpVersion httpVersion = connect && proxyServer .isForceHttp10 () ? HttpVersion .HTTP_1_0 : HttpVersion .HTTP_1_1 ;
132
+ String requestUri = requestUri (uri , proxyServer , connect );
198
133
199
- NettyBody body = body (request , method );
134
+ NettyBody body = body (request , connect );
200
135
201
136
HttpRequest httpRequest ;
202
137
NettyRequest nettyRequest ;
@@ -214,7 +149,7 @@ public NettyRequest newNettyRequest(Request request, Uri uri, boolean forceConne
214
149
215
150
HttpHeaders headers = httpRequest .headers ();
216
151
217
- if (method != HttpMethod . CONNECT ) {
152
+ if (! connect ) {
218
153
// assign headers as configured on request
219
154
for (Entry <String , List <String >> header : request .getHeaders ()) {
220
155
headers .set (header .getKey (), header .getValue ());
@@ -259,7 +194,7 @@ public NettyRequest newNettyRequest(Request request, Uri uri, boolean forceConne
259
194
// don't override authorization but append
260
195
addAuthorizationHeader (headers , systematicAuthorizationHeader (request , uri , realm ));
261
196
262
- setProxyAuthorizationHeader (headers , systematicProxyAuthorizationHeader (request , proxyServer , realm , method ));
197
+ setProxyAuthorizationHeader (headers , systematicProxyAuthorizationHeader (request , proxyServer , realm , connect ));
263
198
264
199
// Add default accept headers
265
200
if (!headers .contains (HttpHeaders .Names .ACCEPT ))
0 commit comments