diff --git a/google-http-client/src/main/java/com/google/api/client/http/HttpStatusCodes.java b/google-http-client/src/main/java/com/google/api/client/http/HttpStatusCodes.java index 1f46eaadc..4f7e18be3 100644 --- a/google-http-client/src/main/java/com/google/api/client/http/HttpStatusCodes.java +++ b/google-http-client/src/main/java/com/google/api/client/http/HttpStatusCodes.java @@ -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; @@ -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 */ @@ -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; diff --git a/google-http-client/src/test/java/com/google/api/client/http/HttpStatusCodesTest.java b/google-http-client/src/test/java/com/google/api/client/http/HttpStatusCodesTest.java new file mode 100644 index 000000000..58b43f024 --- /dev/null +++ b/google-http-client/src/test/java/com/google/api/client/http/HttpStatusCodesTest.java @@ -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)); + } +}