@@ -76,8 +76,7 @@ private Realm kerberosChallenge(Channel channel,//
76
76
FluentCaseInsensitiveStringsMap headers ,//
77
77
Realm realm ,//
78
78
NettyResponseFuture <?> future ,//
79
- boolean proxyInd )
80
- throws NTLMEngineException {
79
+ boolean proxyInd ) throws NTLMEngineException {
81
80
82
81
Uri uri = request .getUri ();
83
82
String host = request .getVirtualHost () == null ? uri .getHost () : request .getVirtualHost ();
@@ -146,9 +145,8 @@ private Realm ntlmChallenge(String wwwAuth, Request request, ProxyServer proxySe
146
145
}
147
146
}
148
147
149
- private Realm ntlmProxyChallenge (String wwwAuth , Request request , ProxyServer proxyServer ,
150
- FluentCaseInsensitiveStringsMap headers , Realm realm , NettyResponseFuture <?> future , boolean proxyInd )
151
- throws NTLMEngineException {
148
+ private Realm ntlmProxyChallenge (String wwwAuth , Request request , ProxyServer proxyServer , FluentCaseInsensitiveStringsMap headers ,
149
+ Realm realm , NettyResponseFuture <?> future , boolean proxyInd ) throws NTLMEngineException {
152
150
future .getAndSetAuth (false );
153
151
headers .remove (HttpHeaders .Names .PROXY_AUTHORIZATION );
154
152
@@ -161,8 +159,8 @@ private Realm ntlmProxyChallenge(String wwwAuth, Request request, ProxyServer pr
161
159
.setMethodName (request .getMethod ()).build ();
162
160
}
163
161
164
- private void addType3NTLMAuthorizationHeader (String auth , FluentCaseInsensitiveStringsMap headers , String username ,
165
- String password , String domain , String workstation , boolean proxyInd ) throws NTLMEngineException {
162
+ private void addType3NTLMAuthorizationHeader (String auth , FluentCaseInsensitiveStringsMap headers , String username , String password ,
163
+ String domain , String workstation , boolean proxyInd ) throws NTLMEngineException {
166
164
headers .remove (authorizationHeaderName (proxyInd ));
167
165
168
166
if (isNonEmpty (auth ) && auth .startsWith ("NTLM " )) {
@@ -176,7 +174,7 @@ private void finishUpdate(final NettyResponseFuture<?> future, Channel channel,
176
174
177
175
boolean keepAlive = future .isKeepAlive ();
178
176
if (expectOtherChunks && keepAlive )
179
- channelManager .drainChannel (channel , future );
177
+ channelManager .drainChannelAndOffer (channel , future );
180
178
else
181
179
channelManager .tryToOfferChannelToPool (channel , keepAlive , channelManager .getPartitionId (future ));
182
180
markAsDone (future , channel );
@@ -228,17 +226,11 @@ private boolean exitAfterHandling401(//
228
226
// NTLM
229
227
newRealm = ntlmChallenge (ntlmAuthenticate , request , proxyServer , request .getHeaders (), realm , future , false );
230
228
231
- // don't forget to reuse channel: NTLM authenticates a connection
232
- future .setReuseChannel (true );
233
-
234
229
} else if (negociate ) {
235
230
// SPNEGO KERBEROS
236
231
newRealm = kerberosChallenge (channel , wwwAuthHeaders , request , proxyServer , request .getHeaders (), realm , future , false );
237
232
if (newRealm == null )
238
233
return true ;
239
- else
240
- // don't forget to reuse channel: KERBEROS authenticates a connection
241
- future .setReuseChannel (true );
242
234
243
235
} else {
244
236
newRealm = new Realm .RealmBuilder ()//
@@ -255,20 +247,22 @@ private boolean exitAfterHandling401(//
255
247
final Request nextRequest = new RequestBuilder (future .getRequest ()).setHeaders (request .getHeaders ()).setRealm (nr ).build ();
256
248
257
249
logger .debug ("Sending authentication to {}" , request .getUri ());
258
- Callback callback = new Callback (future ) {
259
- public void call () throws IOException {
260
- channelManager .drainChannel (channel , future );
250
+ if (future .isKeepAlive ()) {
251
+ if (HttpHeaders .isTransferEncodingChunked (response )) {
252
+ // we must first drain the channel, let's use a fresh one for performing auth
253
+ Channels .setAttribute (channel , new Callback (future ) {
254
+ public void call () throws IOException {
255
+ requestSender .drainChannelAndExecuteNextRequest (channel , future , nextRequest );
256
+ }
257
+ });
258
+ } else {
259
+ future .setReuseChannel (true );
261
260
requestSender .sendNextRequest (nextRequest , future );
262
261
}
263
- };
264
-
265
- if (future .isKeepAlive () && HttpHeaders .isTransferEncodingChunked (response ))
266
- // We must make sure there is no bytes left
267
- // before executing the next request.
268
- Channels .setAttribute (channel , callback );
269
- else
270
- // call might crash with an IOException
271
- callback .call ();
262
+ } else {
263
+ channelManager .closeChannel (channel );
264
+ requestSender .sendNextRequest (nextRequest , future );
265
+ }
272
266
273
267
return true ;
274
268
}
@@ -374,8 +368,8 @@ private boolean exitAfterHandlingConnect(//
374
368
return false ;
375
369
}
376
370
377
- private boolean exitAfterHandlingStatus (Channel channel , NettyResponseFuture <?> future , HttpResponse response ,
378
- AsyncHandler <?> handler , NettyResponseStatus status ) throws IOException , Exception {
371
+ private boolean exitAfterHandlingStatus (Channel channel , NettyResponseFuture <?> future , HttpResponse response , AsyncHandler <?> handler ,
372
+ NettyResponseStatus status ) throws IOException , Exception {
379
373
if (!future .getAndSetStatusReceived (true ) && handler .onStatusReceived (status ) != STATE .CONTINUE ) {
380
374
finishUpdate (future , channel , HttpHeaders .isTransferEncodingChunked (response ));
381
375
return true ;
@@ -393,8 +387,8 @@ private boolean exitAfterHandlingHeaders(Channel channel, NettyResponseFuture<?>
393
387
}
394
388
395
389
// Netty 3: if the response is not chunked, the full body comes with the response
396
- private boolean exitAfterHandlingBody (Channel channel , NettyResponseFuture <?> future , HttpResponse response ,
397
- AsyncHandler <?> handler ) throws Exception {
390
+ private boolean exitAfterHandlingBody (Channel channel , NettyResponseFuture <?> future , HttpResponse response , AsyncHandler <?> handler )
391
+ throws Exception {
398
392
if (!response .isChunked ()) {
399
393
// no chunks expected, exiting
400
394
if (response .getContent ().readableBytes () > 0 )
0 commit comments