TraceRequestHttpHeadersFilter overrides all request headers in Spring Cloud Gateway
See original GitHub issueOops, I’m not sure it is a bug or question.
I’m trying to integrate Spring Cloud Gateway and Spring Cloud Sleuth. In Spring Boot 2.1.2
and Spring Cloud Greenwich.RELEASE
.
I found any of my request Header ‘X-Forward-*’ is missing.
After reading the source code, I found a HeaderFilters in the NettyRoutingFIlter
and the TraceRequestHttpHeadersFilter
was injected.
But TraceRequestHttpHeadersFilter
is so strange. Why is its implementation covered instead of append?
class TraceRequestHttpHeadersFilter extends AbstractHttpHeadersFilter {
private static final Log log = LogFactory.getLog(TraceRequestHttpHeadersFilter.class);
static HttpHeadersFilter create(HttpTracing httpTracing) {
return new TraceRequestHttpHeadersFilter(httpTracing);
}
private TraceRequestHttpHeadersFilter(HttpTracing httpTracing) {
super(httpTracing);
}
public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) {
if (log.isDebugEnabled()) {
log.debug("Will instrument the HTTP request headers");
}
Builder builder = exchange.getRequest().mutate();
Span span = this.handler.handleSend(this.injector, builder);
if (log.isDebugEnabled()) {
log.debug("Client span " + span + " created for the request. New headers are " + builder.build().getHeaders().toSingleValueMap());
}
exchange.getAttributes().put(SPAN_ATTRIBUTE, span);
return new HttpHeaders(builder.build().getHeaders());
}
public boolean supports(Type type) {
return type.equals(Type.REQUEST);
}
}
ps: Forgive my English, I am still trying to learn it.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Spring Cloud Gateway
This listing adds X-Request-red:blue header to the downstream request's headers for all matching requests. AddRequestHeader is aware of the URI variables used ...
Read more >spring-cloud/spring-cloud - Gitter
Override public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) { if ; log.isDebugEnabled()) { log ; "Will instrument the HTTP request headers" ...
Read more >Spring Cloud Gateway: Route and Mutate Request Headers
With Spring Cloud Gateway, we had been able to route and mutate the request with minimal configuration and a single filter.
Read more >ServerHttpRequest$Builder.build - Java - Tabnine
Best Java code snippets using org.springframework.http.server.reactive. ... @Override public HttpHeaders filter(HttpHeaders input, ServerWebExchange ...
Read more >How to get Request header values in Spring Cloud Gateway
You Can write a custom filter for the same. Its just a way around, not sure what is the best way for doing...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, it should be fixed. Please wait for the snapshots and try again.
@marcingrzejszczak The input argument is completely ignored in this method in TraceRequestHttpHeadersFilter, so that means that all updated headers, for example the Forwarded header, is removed from this list.