Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -358,7 +359,7 @@ private Flow<Void> onHttpClientRequest(RequestContext ctx_, HttpClientRequest re
new MapDataBundle.Builder(CAPACITY_3_4)
.add(KnownAddresses.IO_NET_URL, request.getUrl())
.add(KnownAddresses.IO_NET_REQUEST_METHOD, request.getMethod())
.add(KnownAddresses.IO_NET_REQUEST_HEADERS, request.getHeaders());
.add(KnownAddresses.IO_NET_REQUEST_HEADERS, toLowerCaseHeaders(request.getHeaders()));

if (downstreamSampler().isSampled(ctx, request.getRequestId())) {
final Object body = parseHttpClientBody(ctx, request);
Expand Down Expand Up @@ -398,7 +399,7 @@ private Flow<Void> onHttpClientResponse(RequestContext ctx_, HttpClientResponse
final MapDataBundle.Builder bundleBuilder =
new MapDataBundle.Builder(CAPACITY_3_4)
.add(KnownAddresses.IO_NET_RESPONSE_STATUS, Integer.toString(response.getStatus()))
.add(KnownAddresses.IO_NET_RESPONSE_HEADERS, response.getHeaders());
.add(KnownAddresses.IO_NET_RESPONSE_HEADERS, toLowerCaseHeaders(response.getHeaders()));
// ignore the response if not sampled
if (downstreamSampler().isSampled(ctx, response.getRequestId())) {
final Object body = parseHttpClientBody(ctx, response);
Expand Down Expand Up @@ -429,6 +430,19 @@ private Flow<Void> onHttpClientResponse(RequestContext ctx_, HttpClientResponse
}
}

private Map<String, List<String>> toLowerCaseHeaders(final Map<String, List<String>> headers) {
if (headers == null || headers.isEmpty()) {
return headers;
}
final Map<String, List<String>> result = new HashMap<>(headers.size());
for (final Map.Entry<String, List<String>> entry : headers.entrySet()) {
final String key = entry.getKey();
final List<String> value = entry.getValue();
result.put(key == null ? null : key.toLowerCase(Locale.ROOT), value);
}
return result;
}

private Object parseHttpClientBody(
final AppSecRequestContext ctx, final HttpClientPayload payload) {
if (payload.getContentType() == null || payload.getBody() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ class GatewayBridgeSpecification extends DDSpecification {
bundle.size() == (sampled ? 4 : 3)
bundle.get(KnownAddresses.IO_NET_URL) == url
bundle.get(KnownAddresses.IO_NET_REQUEST_METHOD) == method
bundle.get(KnownAddresses.IO_NET_REQUEST_HEADERS) == headers
bundle.get(KnownAddresses.IO_NET_REQUEST_HEADERS) == toLowerCaseHeaders(headers)
if (sampled) {
bundle.get(KnownAddresses.IO_NET_REQUEST_BODY) == ['Hello': 'World!']
}
Expand Down Expand Up @@ -1029,7 +1029,7 @@ class GatewayBridgeSpecification extends DDSpecification {
}
bundle.size() == (sampled ? 3 : 2)
bundle.get(KnownAddresses.IO_NET_RESPONSE_STATUS) == Integer.toString(status)
bundle.get(KnownAddresses.IO_NET_RESPONSE_HEADERS) == headers
bundle.get(KnownAddresses.IO_NET_RESPONSE_HEADERS) == toLowerCaseHeaders(headers)
if (sampled) {
bundle.get(KnownAddresses.IO_NET_RESPONSE_BODY) == ['Hello': 'World!']
}
Expand Down Expand Up @@ -1615,4 +1615,10 @@ class GatewayBridgeSpecification extends DDSpecification {
assert body['test'] == 'this is a test'
}
}

static toLowerCaseHeaders(final Map<String, List<String>> headers) {
return headers.collectEntries {
[(it.key.toLowerCase(Locale.ROOT)): it.value]
}
}
}
Loading