7
7
8
8
import static java .util .logging .Level .FINE ;
9
9
10
- import java .net .InetAddress ;
11
- import java .net .InetSocketAddress ;
12
10
import java .net .URI ;
13
11
import java .net .URISyntaxException ;
14
- import java .util .ArrayList ;
15
- import java .util .Collections ;
16
- import java .util .List ;
17
12
import java .util .logging .Logger ;
18
13
import javax .annotation .Nullable ;
19
- import org .apache .hc .core5 .http .Header ;
20
14
import org .apache .hc .core5 .http .HttpHost ;
21
15
import org .apache .hc .core5 .http .HttpRequest ;
22
- import org .apache .hc .core5 .http .ProtocolVersion ;
23
16
24
- final class ApacheHttpClient5Request {
17
+ public final class ApacheHttpClient5Request {
25
18
26
19
private static final Logger logger = Logger .getLogger (ApacheHttpClient5Request .class .getName ());
27
20
28
21
@ Nullable private final URI uri ;
29
-
30
22
private final HttpRequest delegate ;
31
- @ Nullable private final HttpHost target ;
32
23
33
24
ApacheHttpClient5Request (@ Nullable HttpHost httpHost , HttpRequest httpRequest ) {
34
25
URI calculatedUri = getUri (httpRequest );
@@ -38,34 +29,13 @@ final class ApacheHttpClient5Request {
38
29
uri = calculatedUri ;
39
30
}
40
31
delegate = httpRequest ;
41
- target = httpHost ;
42
32
}
43
33
44
34
/** Returns the actual {@link HttpRequest} being executed by the client. */
45
35
public HttpRequest getDelegate () {
46
36
return delegate ;
47
37
}
48
38
49
- List <String > getHeader (String name ) {
50
- return headersToList (delegate .getHeaders (name ));
51
- }
52
-
53
- // minimize memory overhead by not using streams
54
- static List <String > headersToList (Header [] headers ) {
55
- if (headers .length == 0 ) {
56
- return Collections .emptyList ();
57
- }
58
- List <String > headersList = new ArrayList <>(headers .length );
59
- for (Header header : headers ) {
60
- headersList .add (header .getValue ());
61
- }
62
- return headersList ;
63
- }
64
-
65
- void setHeader (String name , String value ) {
66
- delegate .setHeader (name , value );
67
- }
68
-
69
39
String getMethod () {
70
40
return delegate .getMethod ();
71
41
}
@@ -75,28 +45,6 @@ String getUrl() {
75
45
return uri != null ? uri .toString () : null ;
76
46
}
77
47
78
- String getProtocolName () {
79
- return delegate .getVersion ().getProtocol ();
80
- }
81
-
82
- String getProtocolVersion () {
83
- ProtocolVersion protocolVersion = delegate .getVersion ();
84
- if (protocolVersion .getMinor () == 0 ) {
85
- return Integer .toString (protocolVersion .getMajor ());
86
- }
87
- return protocolVersion .getMajor () + "." + protocolVersion .getMinor ();
88
- }
89
-
90
- @ Nullable
91
- public String getServerAddress () {
92
- return uri == null ? null : uri .getHost ();
93
- }
94
-
95
- @ Nullable
96
- public Integer getServerPort () {
97
- return uri == null ? null : uri .getPort ();
98
- }
99
-
100
48
@ Nullable
101
49
private static URI getUri (HttpRequest httpRequest ) {
102
50
try {
@@ -124,13 +72,4 @@ private static URI getCalculatedUri(HttpHost httpHost, URI uri) {
124
72
return null ;
125
73
}
126
74
}
127
-
128
- @ Nullable
129
- public InetSocketAddress getServerSocketAddress () {
130
- if (target == null ) {
131
- return null ;
132
- }
133
- InetAddress inetAddress = target .getAddress ();
134
- return inetAddress == null ? null : new InetSocketAddress (inetAddress , target .getPort ());
135
- }
136
75
}
0 commit comments