Skip to content

Commit

Permalink
Fixes #258 (Add port to the host header)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitesh Kant committed Oct 28, 2014
1 parent a1a46be commit e4f5663
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

public class HttpClientImpl<I, O> extends RxClientImpl<HttpClientRequest<I>, HttpClientResponse<O>> implements HttpClient<I, O> {

private final String hostHeaderValue;

public HttpClientImpl(String name, ServerInfo serverInfo, Bootstrap clientBootstrap,
PipelineConfigurator<HttpClientResponse<O>, HttpClientRequest<I>> pipelineConfigurator,
ClientConfig clientConfig,
Expand All @@ -44,6 +46,7 @@ public HttpClientImpl(String name, ServerInfo serverInfo, Bootstrap clientBootst
MetricEventsSubject<ClientMetricsEvent<?>> eventsSubject) {
super(name, serverInfo, clientBootstrap, pipelineConfigurator, clientConfig, channelFactory, connectionFactory,
eventsSubject);
hostHeaderValue = prepareHostHeaderValue();
}

public HttpClientImpl(String name, ServerInfo serverInfo, Bootstrap clientBootstrap,
Expand All @@ -52,6 +55,7 @@ public HttpClientImpl(String name, ServerInfo serverInfo, Bootstrap clientBootst
ConnectionPoolBuilder<HttpClientResponse<O>, HttpClientRequest<I>> poolBuilder,
MetricEventsSubject<ClientMetricsEvent<?>> eventsSubject) {
super(name, serverInfo, clientBootstrap, pipelineConfigurator, clientConfig, poolBuilder, eventsSubject);
hostHeaderValue = prepareHostHeaderValue();
}

@Override
Expand All @@ -69,7 +73,7 @@ protected Observable<HttpClientResponse<O>> submit(final HttpClientRequest<I> re
return submit(request, connectionObservable, null == clientConfig
? HttpClientConfig.Builder.newDefaultConfig() : clientConfig);
}

protected Observable<HttpClientResponse<O>> submit(final HttpClientRequest<I> request,
final Observable<ObservableConnection<HttpClientResponse<O>, HttpClientRequest<I>>> connectionObservable,
final ClientConfig config) {
Expand Down Expand Up @@ -133,7 +137,7 @@ private void enrichRequest(HttpClientRequest<I> request, ClientConfig config) {
request.setDynamicUriParts(serverInfo.getHost(), serverInfo.getPort(), false /*Set when we handle https*/);

if(!request.getHeaders().contains(HttpHeaders.Names.HOST)) {
request.getHeaders().add(HttpHeaders.Names.HOST, serverInfo.getHost());
request.getHeaders().add(HttpHeaders.Names.HOST, hostHeaderValue);
}

if (config instanceof HttpClientConfig) {
Expand All @@ -143,4 +147,12 @@ private void enrichRequest(HttpClientRequest<I> request, ClientConfig config) {
}
}
}

private String prepareHostHeaderValue() {
if (serverInfo.getPort() == 80 || serverInfo.getPort() == 443) {
return serverInfo.getHost();
}
// Add port to the host header if the port is not standard port. Issue: https://github.com/ReactiveX/RxNetty/issues/258
return serverInfo.getHost() + ':' + serverInfo.getPort();
}
}

0 comments on commit e4f5663

Please sign in to comment.