File tree Expand file tree Collapse file tree 5 files changed +36
-4
lines changed
test/java/com/ning/http/client/async Expand file tree Collapse file tree 5 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,13 @@ public static interface EntityWriter {
200
200
*/
201
201
public boolean isRedirectEnabled ();
202
202
203
+ /**
204
+ *
205
+ * @return <tt>true></tt> if request's redirectEnabled setting
206
+ * should be used in place of client's
207
+ */
208
+ public boolean isRedirectOverrideSet ();
209
+
203
210
/**
204
211
* Return Per request configuration.
205
212
*
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ private static final class RequestImpl implements Request {
61
61
public ProxyServer proxyServer ;
62
62
private Realm realm ;
63
63
private File file ;
64
- private boolean followRedirects ;
64
+ private Boolean followRedirects ;
65
65
private PerRequestConfig perRequestConfig ;
66
66
private long rangeOffset = 0 ;
67
67
public String charset ;
@@ -92,7 +92,7 @@ public RequestImpl(Request prototype) {
92
92
this .proxyServer = prototype .getProxyServer ();
93
93
this .realm = prototype .getRealm ();
94
94
this .file = prototype .getFile ();
95
- this .followRedirects = prototype .isRedirectEnabled ();
95
+ this .followRedirects = prototype .isRedirectOverrideSet ()? prototype . isRedirectEnabled () : null ;
96
96
this .perRequestConfig = prototype .getPerRequestConfig ();
97
97
this .rangeOffset = prototype .getRangeOffset ();
98
98
this .charset = prototype .getBodyEncoding ();
@@ -259,7 +259,11 @@ public File getFile() {
259
259
}
260
260
261
261
public boolean isRedirectEnabled () {
262
- return followRedirects ;
262
+ return (followRedirects != null && followRedirects );
263
+ }
264
+
265
+ public boolean isRedirectOverrideSet (){
266
+ return followRedirects != null ;
263
267
}
264
268
265
269
public PerRequestConfig getPerRequestConfig () {
Original file line number Diff line number Diff line change @@ -1229,7 +1229,7 @@ public Object call() throws Exception {
1229
1229
return ;
1230
1230
}
1231
1231
1232
- boolean redirectEnabled = request .isRedirectEnabled () ? true : config .isRedirectEnabled ();
1232
+ boolean redirectEnabled = request .isRedirectOverrideSet ()? request . isRedirectEnabled () : config .isRedirectEnabled ();
1233
1233
if (redirectEnabled && (statusCode == 302 || statusCode == 301 || statusCode == 307 )) {
1234
1234
1235
1235
if (future .incrementAndGetCurrentRedirectCount () < config .getMaxRedirects ()) {
Original file line number Diff line number Diff line change @@ -218,6 +218,8 @@ public final static String getHost(URI uri) {
218
218
}
219
219
220
220
public final static URI getRedirectUri (URI uri , String location ) {
221
+ if (location == null )
222
+ throw new IllegalArgumentException ("URI " + uri + " was redirected to null location" );
221
223
URI newUri = uri .resolve (location );
222
224
223
225
String scheme = newUri .getScheme ();
Original file line number Diff line number Diff line change @@ -112,6 +112,25 @@ public void redirected302Test() throws Throwable {
112
112
assertTrue (baseUrl .matches (anyMicrosoftPage ), "response does not show redirection to " + anyMicrosoftPage );
113
113
}
114
114
115
+ @ Test (groups = {"online" , "default_provider" })
116
+ public void notRedirected302Test () throws Throwable {
117
+ isSet .getAndSet (false );
118
+ AsyncHttpClientConfig cg = new AsyncHttpClientConfig .Builder ().setFollowRedirects (true ).build ();
119
+ AsyncHttpClient c = getAsyncHttpClient (cg );
120
+
121
+
122
+ // once
123
+ Response response = c .prepareGet (getTargetUrl ())
124
+ .setFollowRedirects (false )
125
+ .setHeader ("X-redirect" , "http://www.microsoft.com/" )
126
+ .execute ().get ();
127
+
128
+ assertNotNull (response );
129
+ assertEquals (response .getStatusCode (), 302 );
130
+
131
+ c .close ();
132
+ }
133
+
115
134
private String getBaseUrl (URI uri ) {
116
135
String url = uri .toString ();
117
136
int port = uri .getPort ();
You can’t perform that action at this time.
0 commit comments