Skip to content

Commit 501ede8

Browse files
chanseokohelharo
authored andcommitted
fix: redirect on 308 (Permanent Redirect) too (#876)
* Redirect on 308 too * Fix copyright
1 parent a64d3d1 commit 501ede8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

google-http-client/src/main/java/com/google/api/client/http/HttpStatusCodes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public class HttpStatusCodes {
5757
/** Status code for a resource that has temporarily moved to a new URI. */
5858
public static final int STATUS_CODE_TEMPORARY_REDIRECT = 307;
5959

60+
/** Status code for a resource that has permanently moved to a new URI. */
61+
private static final int STATUS_CODE_PERMANENT_REDIRECT = 308;
62+
6063
/** Status code for a request that could not be understood by the server. */
6164
public static final int STATUS_CODE_BAD_REQUEST = 400;
6265

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

110113
/**
111114
* Returns whether the given HTTP response status code is a redirect code {@code 301, 302, 303,
112-
* 307}.
115+
* 307, 308}.
113116
*
114117
* @since 1.11
115118
*/
@@ -119,6 +122,7 @@ public static boolean isRedirect(int statusCode) {
119122
case HttpStatusCodes.STATUS_CODE_FOUND: // 302
120123
case HttpStatusCodes.STATUS_CODE_SEE_OTHER: // 303
121124
case HttpStatusCodes.STATUS_CODE_TEMPORARY_REDIRECT: // 307
125+
case HttpStatusCodes.STATUS_CODE_PERMANENT_REDIRECT: // 308
122126
return true;
123127
default:
124128
return false;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
package com.google.api.client.http;
16+
17+
import junit.framework.TestCase;
18+
19+
/** Tests {@link HttpStatusCodes}. */
20+
public class HttpStatusCodesTest extends TestCase {
21+
22+
public void testIsRedirect_3xx() {
23+
assertTrue(HttpStatusCodes.isRedirect(301));
24+
assertTrue(HttpStatusCodes.isRedirect(302));
25+
assertTrue(HttpStatusCodes.isRedirect(303));
26+
assertTrue(HttpStatusCodes.isRedirect(307));
27+
assertTrue(HttpStatusCodes.isRedirect(308));
28+
}
29+
30+
public void testIsRedirect_non3xx() {
31+
assertFalse(HttpStatusCodes.isRedirect(200));
32+
assertFalse(HttpStatusCodes.isRedirect(401));
33+
assertFalse(HttpStatusCodes.isRedirect(500));
34+
}
35+
}

0 commit comments

Comments
 (0)