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>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.5.x@1746752 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2016-06-03 19:43:48 +00:00
parent 324218e8e6
commit b9ffaad9c7
2 changed files with 59 additions and 1 deletions

View File

@ -35,7 +35,7 @@ import org.apache.http.client.methods.HttpPost;
/**
* 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.HttpPost;
@Immutable
public class LaxRedirectStrategy extends DefaultRedirectStrategy {
public static final LaxRedirectStrategy INSTANCE = new LaxRedirectStrategy();
/**
* Redirectable methods.
*/

View File

@ -0,0 +1,56 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.impl.client;
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());
}
@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));
}
}