You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2016/06/03 19:43:48 UTC
svn commit: r1746752 - in
/httpcomponents/httpclient/branches/4.5.x/httpclient/src:
main/java/org/apache/http/impl/client/LaxRedirectStrategy.java
test/java/org/apache/http/impl/client/TestLaxRedirectStrategy.java
Author: olegk
Date: Fri Jun 3 19:43:48 2016
New Revision: 1746752
URL: http://svn.apache.org/viewvc?rev=1746752&view=rev
Log:
Override LaxRedirectStrategy's INSTANCE field
Surprisingly LaxRedirectStrategy.INSTANCE returns the instance of
DefaultRedirectStrategy. Override the INSTANCE field to return
LaxRedirectStrategy instead. Also add unit tests to LaxRedirectStrategy.
Contributed by Eric Wu <ericwuyi at gmail.com>
Added:
httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/impl/client/TestLaxRedirectStrategy.java
- copied, changed from r1746749, httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java
Modified:
httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java
Modified: httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java?rev=1746752&r1=1746751&r2=1746752&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java (original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java Fri Jun 3 19:43:48 2016
@@ -35,7 +35,7 @@ import org.apache.http.client.methods.Ht
/**
* Lax {@link org.apache.http.client.RedirectStrategy} implementation
- * that automatically redirects all HEAD, GET and POST requests.
+ * that automatically redirects all HEAD, GET, POST, and DELETE requests.
* This strategy relaxes restrictions on automatic redirection of
* POST methods imposed by the HTTP specification.
*
@@ -44,6 +44,8 @@ import org.apache.http.client.methods.Ht
@Immutable
public class LaxRedirectStrategy extends DefaultRedirectStrategy {
+ public static final LaxRedirectStrategy INSTANCE = new LaxRedirectStrategy();
+
/**
* Redirectable methods.
*/
Copied: httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/impl/client/TestLaxRedirectStrategy.java (from r1746749, httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/impl/client/TestLaxRedirectStrategy.java?p2=httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/impl/client/TestLaxRedirectStrategy.java&p1=httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java&r1=1746749&r2=1746752&rev=1746752&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java (original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/impl/client/TestLaxRedirectStrategy.java Fri Jun 3 19:43:48 2016
@@ -24,44 +24,33 @@
* <http://www.apache.org/>.
*
*/
-
package org.apache.http.impl.client;
-import org.apache.http.annotation.Immutable;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestLaxRedirectStrategy {
+
+ @Test
+ public void testIsRedirectable() {
+ assertLaxRedirectable(new LaxRedirectStrategy());
+ }
-/**
- * Lax {@link org.apache.http.client.RedirectStrategy} implementation
- * that automatically redirects all HEAD, GET and POST requests.
- * This strategy relaxes restrictions on automatic redirection of
- * POST methods imposed by the HTTP specification.
- *
- * @since 4.2
- */
-@Immutable
-public class LaxRedirectStrategy extends DefaultRedirectStrategy {
-
- /**
- * Redirectable methods.
- */
- private static final String[] REDIRECT_METHODS = new String[] {
- HttpGet.METHOD_NAME,
- HttpPost.METHOD_NAME,
- HttpHead.METHOD_NAME,
- HttpDelete.METHOD_NAME
- };
-
- @Override
- protected boolean isRedirectable(final String method) {
- for (final String m: REDIRECT_METHODS) {
- if (m.equalsIgnoreCase(method)) {
- return true;
- }
- }
- return false;
+ @Test
+ public void testInstance() {
+ assertLaxRedirectable(LaxRedirectStrategy.INSTANCE);
}
+ private void assertLaxRedirectable(final LaxRedirectStrategy redirectStrategy) {
+ Assert.assertTrue(redirectStrategy.isRedirectable(HttpGet.METHOD_NAME));
+ Assert.assertTrue(redirectStrategy.isRedirectable(HttpHead.METHOD_NAME));
+ Assert.assertFalse(redirectStrategy.isRedirectable(HttpPut.METHOD_NAME));
+ Assert.assertTrue(redirectStrategy.isRedirectable(HttpPost.METHOD_NAME));
+ Assert.assertTrue(redirectStrategy.isRedirectable(HttpDelete.METHOD_NAME));
+ }
}