aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/restapi/RedirectResponse.java
blob: 75b8ea7105ad07ed035e4425d2b1d26097d428d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright Vespa.ai. 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);
    }
}