com.undefinedlabs.scope.rules.headers.OkHttp3HeadersAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scope-rule-okhttp3 Show documentation
Show all versions of scope-rule-okhttp3 Show documentation
Scope is a APM for tests to give engineering teams unprecedented visibility into their CI process to quickly
identify, troubleshoot and fix failed builds.
This artifact contains the classes to instrument OkHttp3 library.
package com.undefinedlabs.scope.rules.headers;
import com.undefinedlabs.scope.rules.http.HttpHeadersAdapter;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.Headers;
import org.apache.commons.lang3.StringUtils;
public class OkHttp3HeadersAdapter implements HttpHeadersAdapter {
private final Headers headers;
public OkHttp3HeadersAdapter(final Headers headers) {
this.headers = headers;
}
@Override
public Iterable> iterator() {
if (headers == null) {
return Collections.unmodifiableMap(new HashMap()).entrySet();
}
final Map headersMap = new HashMap<>();
for (final Map.Entry> entry : headers.toMultimap().entrySet()) {
if (entry.getValue() != null && entry.getValue().size() > 0) {
headersMap.put(entry.getKey(), StringUtils.join(entry.getValue(), "|"));
}
}
return Collections.unmodifiableMap(headersMap).entrySet();
}
}