Skip to content

Commit

Permalink
Changes for the httpclient-4.0 instrumentation module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedell-newrelic committed Feb 15, 2024
1 parent 5f6f6a1 commit 3310801
Showing 1 changed file with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,38 @@
import org.apache.http.Header;
import org.apache.http.HttpResponse;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class InboundWrapper extends ExtendedInboundHeaders {
private final HttpResponse delegate;
private final Header[] headers;

public InboundWrapper(HttpResponse response) {
this.delegate = response;
this.headers = response == null ? null : response.getAllHeaders();
}

@Override
public String getHeader(String name) {
Header[] headers = delegate.getHeaders(name);
if (headers.length > 0) {
return headers[0].getValue();
}
return null;
if (headers == null || name == null) return null;

return Arrays.stream(headers)
.filter(h -> name.equals(h.getName()))
.map(h -> h.getValue())
.findFirst()
.orElse(null);
}

@Override
public List<String> getHeaders(String name) {
Header[] headers = delegate.getHeaders(name);
if (headers.length > 0) {
List<String> result = new ArrayList<>(headers.length);
for (Header header : headers) {
result.add(header.getValue());
}
return result;
}
return null;
if (headers == null || name == null) return null;

List<String> result = Arrays.stream(headers)
.filter(h -> name.equals(h.getName()))
.map(h -> h.getValue())
.collect(Collectors.toList());

return result.isEmpty() ? null : result;
}

@Override
Expand Down

0 comments on commit 3310801

Please sign in to comment.