Skip to content

Commit

Permalink
fix: redirect on 308 (Permanent Redirect) too (#876)
Browse files Browse the repository at this point in the history
* Redirect on 308 too

* Fix copyright
  • Loading branch information
chanseokoh authored and elharo committed Nov 14, 2019
1 parent a64d3d1 commit 501ede8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class HttpStatusCodes {
/** Status code for a resource that has temporarily moved to a new URI. */
public static final int STATUS_CODE_TEMPORARY_REDIRECT = 307;

/** Status code for a resource that has permanently moved to a new URI. */
private static final int STATUS_CODE_PERMANENT_REDIRECT = 308;

/** Status code for a request that could not be understood by the server. */
public static final int STATUS_CODE_BAD_REQUEST = 400;

Expand Down Expand Up @@ -109,7 +112,7 @@ public static boolean isSuccess(int statusCode) {

/**
* Returns whether the given HTTP response status code is a redirect code {@code 301, 302, 303,
* 307}.
* 307, 308}.
*
* @since 1.11
*/
Expand All @@ -119,6 +122,7 @@ public static boolean isRedirect(int statusCode) {
case HttpStatusCodes.STATUS_CODE_FOUND: // 302
case HttpStatusCodes.STATUS_CODE_SEE_OTHER: // 303
case HttpStatusCodes.STATUS_CODE_TEMPORARY_REDIRECT: // 307
case HttpStatusCodes.STATUS_CODE_PERMANENT_REDIRECT: // 308
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2019 Google LLC
*
* Licensed 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.
*/

package com.google.api.client.http;

import junit.framework.TestCase;

/** Tests {@link HttpStatusCodes}. */
public class HttpStatusCodesTest extends TestCase {

public void testIsRedirect_3xx() {
assertTrue(HttpStatusCodes.isRedirect(301));
assertTrue(HttpStatusCodes.isRedirect(302));
assertTrue(HttpStatusCodes.isRedirect(303));
assertTrue(HttpStatusCodes.isRedirect(307));
assertTrue(HttpStatusCodes.isRedirect(308));
}

public void testIsRedirect_non3xx() {
assertFalse(HttpStatusCodes.isRedirect(200));
assertFalse(HttpStatusCodes.isRedirect(401));
assertFalse(HttpStatusCodes.isRedirect(500));
}
}

0 comments on commit 501ede8

Please sign in to comment.