summaryrefslogtreecommitdiffstats
path: root/container-core/src
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-04-30 09:56:32 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-04-30 09:56:32 +0200
commit5152b13d01819a3baec82728df1adb2cec3c7d2d (patch)
treeba139ad381c34d2be29b25b218b7e4c58d864ab2 /container-core/src
parent49d1cc7e0d7a724e483d7bae8cd5febff2a96df1 (diff)
Add redirect response
Diffstat (limited to 'container-core/src')
-rw-r--r--container-core/src/main/java/com/yahoo/restapi/RedirectResponse.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/container-core/src/main/java/com/yahoo/restapi/RedirectResponse.java b/container-core/src/main/java/com/yahoo/restapi/RedirectResponse.java
new file mode 100644
index 00000000000..23c6a238f95
--- /dev/null
+++ b/container-core/src/main/java/com/yahoo/restapi/RedirectResponse.java
@@ -0,0 +1,27 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.restapi;
+
+import com.yahoo.jdisc.Response;
+
+import java.net.URI;
+
+/**
+ * A HTTP redirect response
+ *
+ * @author bjorncs
+ */
+public class RedirectResponse extends MessageResponse {
+
+ private RedirectResponse(int statusCode, URI location) {
+ super(statusCode, "Moved to " + location.toString());
+ headers().add("Location", location.toString());
+ }
+
+ public static RedirectResponse found(URI location) {
+ return new RedirectResponse(Response.Status.FOUND, location);
+ }
+
+ public static RedirectResponse movedPermanently(URI location) {
+ return new RedirectResponse(Response.Status.MOVED_PERMANENTLY, location);
+ }
+}