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 package org.apache.http.impl.client;
29
30 import java.net.URI;
31
32 import org.apache.http.HttpRequest;
33 import org.apache.http.HttpResponse;
34 import org.apache.http.ProtocolException;
35 import org.apache.http.annotation.Contract;
36 import org.apache.http.annotation.ThreadingBehavior;
37 import org.apache.http.client.RedirectHandler;
38 import org.apache.http.client.RedirectStrategy;
39 import org.apache.http.client.methods.HttpGet;
40 import org.apache.http.client.methods.HttpHead;
41 import org.apache.http.client.methods.HttpUriRequest;
42 import org.apache.http.protocol.HttpContext;
43
44
45
46
47 @Contract(threading = ThreadingBehavior.IMMUTABLE)
48 @Deprecated
49 class DefaultRedirectStrategyAdaptor implements RedirectStrategy {
50
51 private final RedirectHandler handler;
52
53 public DefaultRedirectStrategyAdaptor(final RedirectHandler handler) {
54 super();
55 this.handler = handler;
56 }
57
58 @Override
59 public boolean isRedirected(
60 final HttpRequest request,
61 final HttpResponse response,
62 final HttpContext context) throws ProtocolException {
63 return this.handler.isRedirectRequested(response, context);
64 }
65
66 @Override
67 public HttpUriRequest getRedirect(
68 final HttpRequest request,
69 final HttpResponse response,
70 final HttpContext context) throws ProtocolException {
71 final URI uri = this.handler.getLocationURI(response, context);
72 final String method = request.getRequestLine().getMethod();
73 if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
74 return new HttpHead(uri);
75 } else {
76 return new HttpGet(uri);
77 }
78 }
79
80 public RedirectHandler getHandler() {
81 return this.handler;
82 }
83
84 }