16
16
package org .asynchttpclient ;
17
17
18
18
import io .netty .buffer .ByteBuf ;
19
+ import io .netty .channel .unix .DomainSocketAddress ;
19
20
import io .netty .handler .codec .http .DefaultHttpHeaders ;
20
21
import io .netty .handler .codec .http .HttpHeaders ;
21
22
import io .netty .handler .codec .http .cookie .Cookie ;
27
28
import org .asynchttpclient .request .body .generator .BodyGenerator ;
28
29
import org .asynchttpclient .request .body .generator .ReactiveStreamsBodyGenerator ;
29
30
import org .asynchttpclient .request .body .multipart .Part ;
31
+ import org .asynchttpclient .resolver .DefaultDomainNameResolver ;
30
32
import org .asynchttpclient .uri .Uri ;
31
33
import org .asynchttpclient .util .UriEncoder ;
32
34
import org .reactivestreams .Publisher ;
36
38
import java .io .File ;
37
39
import java .io .InputStream ;
38
40
import java .net .InetAddress ;
41
+ import java .net .InetSocketAddress ;
42
+ import java .net .SocketAddress ;
39
43
import java .nio .ByteBuffer ;
40
44
import java .nio .charset .Charset ;
41
45
import java .util .*;
@@ -56,6 +60,7 @@ public abstract class RequestBuilderBase<T extends RequestBuilderBase<T>> {
56
60
private final static Logger LOGGER = LoggerFactory .getLogger (RequestBuilderBase .class );
57
61
private static final Uri DEFAULT_REQUEST_URL = Uri .create ("http://localhost" );
58
62
public static NameResolver <InetAddress > DEFAULT_NAME_RESOLVER = new DefaultNameResolver (ImmediateEventExecutor .INSTANCE );
63
+ public static NameResolver <DomainSocketAddress > DEFAULT_DOMAIN_NAME_RESOLVER = new DefaultDomainNameResolver (ImmediateEventExecutor .INSTANCE );
59
64
// builder only fields
60
65
protected UriEncoder uriEncoder ;
61
66
protected List <Param > queryParams ;
@@ -64,8 +69,8 @@ public abstract class RequestBuilderBase<T extends RequestBuilderBase<T>> {
64
69
// request fields
65
70
protected String method ;
66
71
protected Uri uri ;
67
- protected InetAddress address ;
68
- protected InetAddress localAddress ;
72
+ protected SocketAddress address ;
73
+ protected SocketAddress localAddress ;
69
74
protected HttpHeaders headers ;
70
75
protected ArrayList <Cookie > cookies ;
71
76
protected byte [] byteData ;
@@ -87,6 +92,7 @@ public abstract class RequestBuilderBase<T extends RequestBuilderBase<T>> {
87
92
protected Charset charset ;
88
93
protected ChannelPoolPartitioning channelPoolPartitioning = ChannelPoolPartitioning .PerHostChannelPoolPartitioning .INSTANCE ;
89
94
protected NameResolver <InetAddress > nameResolver = DEFAULT_NAME_RESOLVER ;
95
+ protected NameResolver <DomainSocketAddress > domainNameResolver = DEFAULT_DOMAIN_NAME_RESOLVER ;
90
96
91
97
protected RequestBuilderBase (String method , boolean disableUrlEncoding ) {
92
98
this (method , disableUrlEncoding , true );
@@ -136,6 +142,7 @@ protected RequestBuilderBase(Request prototype, boolean disableUrlEncoding, bool
136
142
this .charset = prototype .getCharset ();
137
143
this .channelPoolPartitioning = prototype .getChannelPoolPartitioning ();
138
144
this .nameResolver = prototype .getNameResolver ();
145
+ this .domainNameResolver = prototype .getDomainNameResolver ();
139
146
}
140
147
141
148
@ SuppressWarnings ("unchecked" )
@@ -144,6 +151,9 @@ private T asDerivedType() {
144
151
}
145
152
146
153
public T setUrl (String url ) {
154
+ if (!url .contains ("://" )){
155
+ url = "http://127.0.0.1:80" + url ;
156
+ }
147
157
return setUri (Uri .create (url ));
148
158
}
149
159
@@ -153,11 +163,20 @@ public T setUri(Uri uri) {
153
163
}
154
164
155
165
public T setAddress (InetAddress address ) {
156
- this .address = address ;
166
+ this .address = new InetSocketAddress ( address , 0 ) ;
157
167
return asDerivedType ();
158
168
}
159
169
160
170
public T setLocalAddress (InetAddress address ) {
171
+ this .localAddress = new InetSocketAddress (address ,0 );
172
+ return asDerivedType ();
173
+ }
174
+ public T setDomainAddress (DomainSocketAddress address ) {
175
+ this .address = address ;
176
+ return asDerivedType ();
177
+ }
178
+
179
+ public T setDomainLocalAddress (DomainSocketAddress address ) {
161
180
this .localAddress = address ;
162
181
return asDerivedType ();
163
182
}
@@ -534,6 +553,11 @@ public T setNameResolver(NameResolver<InetAddress> nameResolver) {
534
553
return asDerivedType ();
535
554
}
536
555
556
+ public T setDomainNameResolver (NameResolver <DomainSocketAddress > nameResolver ) {
557
+ this .domainNameResolver = nameResolver ;
558
+ return asDerivedType ();
559
+ }
560
+
537
561
public T setSignatureCalculator (SignatureCalculator signatureCalculator ) {
538
562
this .signatureCalculator = signatureCalculator ;
539
563
return asDerivedType ();
@@ -580,6 +604,7 @@ private RequestBuilderBase<?> executeSignatureCalculator() {
580
604
rb .charset = this .charset ;
581
605
rb .channelPoolPartitioning = this .channelPoolPartitioning ;
582
606
rb .nameResolver = this .nameResolver ;
607
+ rb .domainNameResolver = this .domainNameResolver ;
583
608
Request unsignedRequest = rb .build ();
584
609
signatureCalculator .calculateAndAddSignature (unsignedRequest , rb );
585
610
return rb ;
@@ -642,6 +667,7 @@ public Request build() {
642
667
rb .rangeOffset ,
643
668
rb .charset ,
644
669
rb .channelPoolPartitioning ,
645
- rb .nameResolver );
670
+ rb .nameResolver ,
671
+ rb .domainNameResolver );
646
672
}
647
673
}
0 commit comments