private void verifyProxyAndDownstreamRequestHeaders() { HttpHeaders proxyRequestHeaders = extractHeadersFromRawRequestOrResponse(proxyServerRawRequest.toString()); HttpHeaders downstreamRequestHeaders = extractHeadersFromRawRequestOrResponse(downstreamServerRawRequest.toString()); // Verify that request headers are passed downstream as expected. The host may change, but content length // and transfer encoding in particular should be unchanged as it passes through the proxy. assertThat(proxyRequestHeaders.get(HttpHeaders.Names.HOST)).isEqualTo("localhost"); assertThat(proxyRequestHeaders.get(CONTENT_LENGTH)).isEqualTo(downstreamRequestHeaders.get(CONTENT_LENGTH)); assertThat(proxyRequestHeaders.get(TRANSFER_ENCODING)).isEqualTo(downstreamRequestHeaders.get(TRANSFER_ENCODING)); assertThat(downstreamRequestHeaders.get(HttpHeaders.Names.HOST)).isEqualTo("127.0.0.1:" + downstreamServerConfig.endpointsPort()); // Sanity check that the expected header was passed. assertThat(proxyRequestHeaders.get(SOME_EXPECTED_REQUEST_HEADER.getKey())).isEqualTo(SOME_EXPECTED_REQUEST_HEADER.getValue()); assertThat(downstreamRequestHeaders.get(SOME_EXPECTED_REQUEST_HEADER.getKey())).isEqualTo(SOME_EXPECTED_REQUEST_HEADER.getValue()); // Verify that trace info was added to downstream call by the proxy. assertThat(downstreamRequestHeaders.get("X-B3-TraceId")).isNotNull(); assertThat(downstreamRequestHeaders.get("X-B3-SpanId")).isNotNull(); assertThat(downstreamRequestHeaders.get("X-B3-ParentSpanId")).isNotNull(); assertThat(downstreamRequestHeaders.get("X-B3-Sampled")).isNotNull(); // Verify that the proxy and downstream requests have the same headers (barring the tracing headers and the // host header, which can be different between proxy and downstream and we've already accounted for above). Map<String, List<String>> normalizedProxyHeaders = headersToMap(copyWithMutableHeadersRemoved(proxyRequestHeaders)); Map<String, List<String>> normalizedDownstreamHeaders = headersToMap(copyWithMutableHeadersRemoved(downstreamRequestHeaders)); assertThat(normalizedProxyHeaders).isEqualTo(normalizedDownstreamHeaders); }
headersToMap(copyWithMutableHeadersRemoved(proxyResponseHeaders)); Map<String, List<String>> normalizedDownstreamHeaders = headersToMap(copyWithMutableHeadersRemoved(downstreamResponseHeaders));