question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TraceRequestHttpHeadersFilter overrides all request headers in Spring Cloud Gateway

See original GitHub issue

Oops, 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
marcingrzejszczakcommented, Jan 29, 2019

Ok, it should be fixed. Please wait for the snapshots and try again.

3reactions
martinvissercommented, Jan 28, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found