Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better impl of remote ip address tracking.

  • Loading branch information...
commit e55a99c715f5aa753fdc71cec29fc915d01ad23a 1 parent bd1f1cf
@nicoo authored
View
26 src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java
@@ -1546,7 +1546,12 @@ private final boolean updateStatusAndInterrupt(AsyncHandler handler, HttpRespons
}
@SuppressWarnings("unchecked")
- private final boolean updateHeadersAndInterrupt(AsyncHandler handler, HttpResponseHeaders c) throws Exception {
+ private final boolean updateHeadersAndInterrupt(final NettyResponseFuture<?> future, AsyncHandler handler, HttpResponseHeaders c) throws Exception {
+ if (future.getRemoteAddress() != null) {
+ FluentCaseInsensitiveStringsMap tmpHeaders = c.getHeaders();
+ tmpHeaders.add("LINKFLUENCE-REMOTE-ADDR", future.getRemoteAddress());
+ c = new ResponseHeaders(future.getURI(), future.getHttpResponse(), this, tmpHeaders);
+ }
return handler.onHeadersReceived(c) != STATE.CONTINUE;
}
@@ -2314,20 +2319,9 @@ public Object call() throws Exception {
if (!future.getAndSetStatusReceived(true) && updateStatusAndInterrupt(handler, status)) {
finishUpdate(future, ctx, response.isChunked());
return;
- } else if (response.getHeaders().size() > 0) {
- FluentCaseInsensitiveStringsMap tmpHeaders = responseHeaders.getHeaders();
- SocketAddress sa = ctx.getChannel().getRemoteAddress();
- if(sa instanceof InetSocketAddress){
- InetSocketAddress isa = (InetSocketAddress) sa;
- tmpHeaders.add("LINKFLUENCE-REMOTE-ADDR", isa.getAddress().getHostAddress());
- responseHeaders = new ResponseHeaders(future.getURI(), response, NettyAsyncHttpProvider.this, tmpHeaders);
- }
-
- if (updateHeadersAndInterrupt(handler, responseHeaders)) {
-
- finishUpdate(future, ctx, response.isChunked());
- return;
- }
+ } else if (response.getHeaders().size() > 0 && updateHeadersAndInterrupt(future, handler, responseHeaders)) {
+ finishUpdate(future, ctx, response.isChunked());
+ return;
} else if (!response.isChunked()) {
if (response.getContent().readableBytes() != 0) {
updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), response, NettyAsyncHttpProvider.this, true));
@@ -2349,7 +2343,7 @@ public Object call() throws Exception {
if (chunk.isLast() || updateBodyAndInterrupt(future, handler,
new ResponseBodyPart(future.getURI(), null, NettyAsyncHttpProvider.this, chunk, chunk.isLast()))) {
if (chunk instanceof DefaultHttpChunkTrailer) {
- updateHeadersAndInterrupt(handler, new ResponseHeaders(future.getURI(),
+ updateHeadersAndInterrupt(future, handler, new ResponseHeaders(future.getURI(),
future.getHttpResponse(), NettyAsyncHttpProvider.this, (HttpChunkTrailer) chunk));
}
finishUpdate(future, ctx, !chunk.isLast());
View
4 src/main/java/com/ning/http/client/providers/netty/NettyConnectListener.java
@@ -81,7 +81,9 @@ public final void operationComplete(ChannelFuture f) throws Exception {
throw new ConnectException("HostnameVerifier exception.");
}
}
-
+ future.setRemoteAddress(InetSocketAddress.class.cast(channel.getRemoteAddress())
+ .getAddress()
+ .getHostAddress());
future.provider().writeRequest(f.getChannel(), config, future, nettyRequest);
} else {
Throwable cause = f.getCause();
View
10 src/main/java/com/ning/http/client/providers/netty/NettyResponseFuture.java
@@ -91,6 +91,7 @@
private boolean allowConnect = false;
private final ConnectionPoolKeyStrategy connectionPoolKeyStrategy;
private final ProxyServer proxyServer;
+ private String remoteAddress;
public NettyResponseFuture(URI uri,
Request request,
@@ -476,6 +477,15 @@ protected boolean canRetry() {
public void setRequest(Request request) {
this.request = request;
}
+
+ public void setRemoteAddress(String remoteAddress){
+ this.remoteAddress = remoteAddress;
+ }
+
+ public String getRemoteAddress(){
+ return remoteAddress;
+ }
+
/**
* Return true if the {@link Future} cannot be recovered. There is some scenario where a connection can be
Please sign in to comment.
Something went wrong with that request. Please try again.