Example usage for io.netty.handler.codec.http HttpHeaders copy

List of usage examples for io.netty.handler.codec.http HttpHeaders copy

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpHeaders copy.

Prototype

public HttpHeaders copy() 

Source Link

Document

Returns a deep copy of the passed in HttpHeaders .

Usage

From source file:org.springframework.cloud.sleuth.instrument.web.client.TraceWebClientAutoConfiguration.java

License:Apache License

Mono<HttpClientResponse> wrapHttpClientRequestSending(ProceedingJoinPoint pjp,
        BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>> function)
        throws Throwable {
    // add headers and set CS
    final Span currentSpan = this.tracer.currentSpan();
    final AtomicReference<Span> span = new AtomicReference<>();
    BiFunction<HttpClientRequest, NettyOutbound, Publisher<Void>> combinedFunction = (req, nettyOutbound) -> {
        try (Tracer.SpanInScope spanInScope = this.tracer.withSpanInScope(currentSpan)) {
            io.netty.handler.codec.http.HttpHeaders originalHeaders = req.requestHeaders().copy();
            io.netty.handler.codec.http.HttpHeaders tracedHeaders = req.requestHeaders();
            span.set(this.handler.handleSend(this.injector, tracedHeaders, req));
            if (log.isDebugEnabled()) {
                log.debug("Handled send of " + span.get());
            }//w  w w . j av a2s. c o  m
            io.netty.handler.codec.http.HttpHeaders addedHeaders = tracedHeaders.copy();
            originalHeaders.forEach(header -> addedHeaders.remove(header.getKey()));
            try (Tracer.SpanInScope clientInScope = this.tracer.withSpanInScope(span.get())) {
                if (log.isDebugEnabled()) {
                    log.debug("Created a new client span for Netty client");
                }
                return handle(function, new TracedHttpClientRequest(req, addedHeaders), nettyOutbound);
            }
        }
    };
    // run
    Mono<HttpClientResponse> responseMono = (Mono<HttpClientResponse>) pjp
            .proceed(new Object[] { combinedFunction });
    // get response
    return responseMono.doOnSuccessOrError((httpClientResponse, throwable) -> {
        try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.get())) {
            // status codes and CR
            if (span.get() != null) {
                this.handler.handleReceive(httpClientResponse, throwable, span.get());
                if (log.isDebugEnabled()) {
                    log.debug("Setting client sent spans");
                }
            }
        }
    });
}