Skip to content

Commit

Permalink
add remote address when reuse connection
Browse files Browse the repository at this point in the history
  • Loading branch information
sxci committed Nov 13, 2020
1 parent af316fe commit d0a5ab5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/com/qiniu/http/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ public void connectStart(Call call, InetSocketAddress inetSocketAddress, Proxy p
tag.ip = inetSocketAddress + "";
}
});
builder.addNetworkInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
okhttp3.Response response = chain.proceed(request);
IpTag tag = (IpTag) request.tag();
if (tag.ip != null && tag.ip.length() > 5) {
return response;
}
try {
tag.ip = chain.connection().socket().getRemoteSocketAddress().toString();
} catch (Exception e) {
// ingore
}
return response;
}
});
builder.addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Expand Down

0 comments on commit d0a5ab5

Please sign in to comment.