header add Twice Error
jinyulei0710 opened this issue · 5 comments
jinyulei0710 commented
when I use this interceptor to log,The same Header showed twice.
jinyulei0710 commented
Headers headers = request.headers();
Set names = headers.names();
Iterator iterator = names.iterator();
Request.Builder requestBuilder = request.newBuilder();
for (String key : headerMap.keySet()) {
String value = headerMap.get(key);
requestBuilder.addHeader(key, value);
}
while (iterator.hasNext()) {
String name = iterator.next();
requestBuilder.addHeader(name, headers.get(name));
}
jinyulei0710 commented
@ihsanbal why you add header twice?
orcchg commented
Same to me. Headers are duplicating.
I had fallen back to 2.0.2
orcchg commented
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
HashMap<String, String> headerMap = builder.getHeaders();
if (headerMap.size() > 0) {
Headers headers = request.headers();
Set<String> names = headers.names();
Iterator<String> iterator = names.iterator();
Request.Builder requestBuilder = request.newBuilder();
for (String key : headerMap.keySet()) {
String value = headerMap.get(key);
requestBuilder.addHeader(key, value);
}
while (iterator.hasNext()) {
String name = iterator.next();
requestBuilder.addHeader(name, headers.get(name));
}
request = requestBuilder.build();
}```
ihsanbal commented
I am going to solve this problem ASAP. Thanks for reporting.