All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.undefinedlabs.scope.rules.headers.OkHttp3HeadersAdapter Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 0.15.1-beta.2
Show newest version
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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy