Allow REST APIs to return HTTP redirects
Eventually we can expose avatar links under /accounts/{id}/avatar
instead of /avatar/{id}. This better fits with the path space of
the server.
Change-Id: I461ea540310622b5d769bf1951a72cf34ad60a0e
This commit is contained in:
@@ -35,6 +35,11 @@ public abstract class Response<T> {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/** HTTP 302 Found: temporary redirect to another URL. */
|
||||
public static Redirect redirect(String location) {
|
||||
return new Redirect(location);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static <T> T unwrap(T obj) {
|
||||
while (obj instanceof Response) {
|
||||
@@ -90,4 +95,33 @@ public abstract class Response<T> {
|
||||
return "[204 No Content] None";
|
||||
}
|
||||
}
|
||||
|
||||
/** An HTTP redirect to another location. */
|
||||
public static final class Redirect {
|
||||
private final String location;
|
||||
|
||||
private Redirect(String url) {
|
||||
this.location = url;
|
||||
}
|
||||
|
||||
public String location() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return location.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Redirect
|
||||
&& ((Redirect) o).location.equals(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[302 Redirect] %s", location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user