File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
src/main/java/com/ning/http/client Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -160,4 +160,9 @@ public RequestBuilder setVirtualHost(String virtualHost) {
160
160
public RequestBuilder setFollowRedirects (boolean followRedirects ) {
161
161
return super .setFollowRedirects (followRedirects );
162
162
}
163
+
164
+ @ Override
165
+ public RequestBuilder addOrReplaceCookie (Cookie c ) {
166
+ return super .addOrReplaceCookie (c );
167
+ }
163
168
}
Original file line number Diff line number Diff line change @@ -563,4 +563,23 @@ private boolean allowBody(String method) {
563
563
return true ;
564
564
}
565
565
}
566
+
567
+ public T addOrReplaceCookie (Cookie cookie ) {
568
+ String cookieKey =cookie .getName ();
569
+ boolean replace =false ;
570
+ int index =0 ;
571
+ for (Cookie c : request .cookies ) {
572
+ if (c .getName ().equals (cookieKey )){
573
+ replace =true ;
574
+ break ;
575
+ };
576
+ index ++;
577
+ }
578
+ if (replace ) {
579
+ ((ArrayList <Cookie >)request .cookies ).set (index , cookie );
580
+ } else {
581
+ request .cookies .add (cookie );
582
+ }
583
+ return derived .cast (this );
584
+ }
566
585
}
Original file line number Diff line number Diff line change @@ -1161,6 +1161,15 @@ public Object call() throws Exception {
1161
1161
final String newUrl = uri .toString ();
1162
1162
1163
1163
log .debug ("Redirecting to {}" , newUrl );
1164
+ for (String cookieStr : future .getHttpResponse ().getHeaders (HttpHeaders .Names .SET_COOKIE )){
1165
+ Cookie c =AsyncHttpProviderUtils .parseCookie (cookieStr );
1166
+ nBuilder .addOrReplaceCookie (c );
1167
+ }
1168
+ for (String cookieStr : future .getHttpResponse ().getHeaders (HttpHeaders .Names .SET_COOKIE2 )){
1169
+ Cookie c =AsyncHttpProviderUtils .parseCookie (cookieStr );
1170
+ nBuilder .addOrReplaceCookie (c );
1171
+ }
1172
+
1164
1173
1165
1174
AsyncCallable ac = new AsyncCallable (future ) {
1166
1175
public Object call () throws Exception {
You can’t perform that action at this time.
0 commit comments