forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFollowRedirectsFilter.java
More file actions
34 lines (29 loc) · 1.41 KB
/
Copy pathFollowRedirectsFilter.java
File metadata and controls
34 lines (29 loc) · 1.41 KB
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
28
29
30
31
32
33
34
package com.github.dockerjava.jaxrs.filter;
import java.io.IOException;
import java.io.InputStream;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.core.Response;
/**
* Default implementation of RedirectStrategy honors the restrictions on automatic redirection of entity enclosing methods such as POST and
* PUT imposed by the HTTP specification. 302 Moved Temporarily, 301 Moved Permanently and 307 Temporary Redirect status codes will result
* in an automatic redirect of HEAD and GET methods only.
*
* {@link org.apache.http.impl.client.DefaultRedirectStrategy}
*
* This filter allows arbitrary redirection for other methods.
*/
public class FollowRedirectsFilter implements ClientResponseFilter {
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
if (!responseContext.getStatusInfo().getFamily().equals(Response.Status.Family.REDIRECTION)) {
return;
}
Response resp = requestContext.getClient().target(responseContext.getLocation()).request()
.method(requestContext.getMethod());
responseContext.setEntityStream((InputStream) resp.getEntity());
responseContext.setStatusInfo(resp.getStatusInfo());
responseContext.setStatus(resp.getStatus());
}
}