2323import io .vertx .core .http .HttpVersion ;
2424import io .vertx .core .http .impl .HttpServerRequestInternal ;
2525import io .vertx .core .impl .ContextInternal ;
26+ import io .vertx .core .net .HostAndPort ;
27+ import io .vertx .core .net .impl .HostAndPortImpl ;
2628import io .vertx .core .streams .Pipe ;
2729import io .vertx .httpproxy .Body ;
2830import io .vertx .httpproxy .ProxyRequest ;
@@ -51,7 +53,7 @@ public class ProxiedRequest implements ProxyRequest {
5153 private String uri ;
5254 private final String absoluteURI ;
5355 private Body body ;
54- private String authority ;
56+ private HostAndPort authority ;
5557 private final MultiMap headers ;
5658 HttpClientRequest request ;
5759 private final HttpServerRequest proxiedRequest ;
@@ -77,7 +79,7 @@ public ProxiedRequest(HttpServerRequest proxiedRequest) {
7779 this .absoluteURI = proxiedRequest .absoluteURI ();
7880 this .proxiedRequest = proxiedRequest ;
7981 this .context = (ContextInternal ) ((HttpServerRequestInternal ) proxiedRequest ).context ();
80- this .authority = proxiedRequest .host ();
82+ this .authority = proxiedRequest .authority ();
8183 }
8284
8385 @ Override
@@ -110,13 +112,13 @@ public ProxyRequest setBody(Body body) {
110112 @ Override
111113 public ProxyRequest setAuthority (String authority ) {
112114 Objects .requireNonNull (authority );
113- this .authority = authority ;
115+ this .authority = HostAndPortImpl . parseHostAndPort ( authority , - 1 ) ;
114116 return this ;
115117 }
116118
117119 @ Override
118120 public String getAuthority () {
119- return authority ;
121+ return authority . toString () ;
120122 }
121123
122124 @ Override
@@ -174,32 +176,10 @@ void sendRequest(Handler<AsyncResult<ProxyResponse>> responseHandler) {
174176 }
175177
176178 //
177- String proxiedAuthority = proxiedRequest .host ();
178- int idx = proxiedAuthority .indexOf (':' );
179- String proxiedHost ;
180- int proxiedPort ;
181- if (idx == -1 ) {
182- proxiedHost = proxiedAuthority ;
183- proxiedPort = -1 ;
184- } else {
185- proxiedHost = proxiedAuthority .substring (0 , idx );
186- proxiedPort = Integer .parseInt (proxiedAuthority .substring (idx + 1 ));
187- }
188-
189- String host ;
190- int port ;
191- idx = authority .indexOf (':' );
192- if (idx == -1 ) {
193- host = authority ;
194- port = -1 ;
195- } else {
196- host = authority .substring (0 , idx );
197- port = Integer .parseInt (authority .substring (idx + 1 ));
198- }
199- request .setHost (host );
200- request .setPort (port == -1 ? (request .absoluteURI ().startsWith ("https://" ) ? 443 : 80 ) : port );
201- if (!proxiedHost .equals (host ) || proxiedPort != port ) {
202- request .putHeader (X_FORWARDED_HOST , proxiedAuthority );
179+ HostAndPort proxiedAuthority = proxiedRequest .authority ();
180+ request .authority (authority );
181+ if (!proxiedAuthority .host ().equals (authority .host ()) || proxiedAuthority .port () != authority .port ()) {
182+ request .putHeader (X_FORWARDED_HOST , proxiedAuthority .toString ());
203183 }
204184
205185 long len = body .length ();
0 commit comments