Source:
<code>private Function<HttpResponse, Mono<HttpResponse>> logResponseDelegate(final ClientLogger logger, final URL url, final long startNs) { return (HttpResponse response) -> { long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs); String contentLengthString = response.getHeaderValue("Content-Length"); String bodySize; if (contentLengthString == null || contentLengthString.isEmpty()) { bodySize = "unknown-length"; } else { bodySize = contentLengthString + "-byte"; } if (httpLogOptions.getLogLevel().shouldLogUrl()) { logger.info("<-- ({} ms, body)", response.getStatusCode(), url, tookMs, bodySize); } if (httpLogOptions.getLogLevel().shouldLogHeaders()) { StringBuilder sb = new StringBuilder(); for (HttpHeader header : response.getHeaders()) { sb.append(header.getName()).append(":"); if (httpLogOptions.getAllowedHeaderNames().contains(header.getName())) { sb.append(header.getValue()); } else { sb.append(REDACTED_PLACEHOLDER); } } <START> logger.info(sb.toString()); <END> } if (httpLogOptions.getLogLevel().shouldLogBody()) { long contentLength = getContentLength(response.getHeaders()); final String contentTypeHeader = response.getHeaderValue("Content-Type"); if (!"application/octet-stream".equalsIgnoreCase(contentTypeHeader) && contentLength != 0 && contentLength < MAX_BODY_LOG_SIZE) { final HttpResponse bufferedResponse = response.buffer(); return bufferedResponse.getBodyAsString().map(bodyStr -> { bodyStr = prettyPrintIfNeeded(logger, contentTypeHeader, bodyStr); logger.info("Response body:\n{}", bodyStr); logger.info("<-- END HTTP"); return bufferedResponse; }).switchIfEmpty(Mono.defer(() -> Mono.just(bufferedResponse))); } else { logger.info("(body content not logged)"); logger.info("<-- END HTTP"); } } else { logger.info("<-- END HTTP"); } return Mono.just(response); }; }</code><technical_language>This header concatenation code centralised in this class duplicated for request response headers</technical_language>

Target:
private Function<HttpResponse, Mono<HttpResponse>> logResponseDelegate(final ClientLogger logger, final URL url, final long startNs) { return (HttpResponse response) -> { long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs); String contentLengthString = response.getHeaderValue("Content-Length"); String bodySize; if (contentLengthString == null || contentLengthString.isEmpty()) { bodySize = "unknown-length"; } else { bodySize = contentLengthString + "-byte"; } HttpLogDetailLevel httpLogLevel = httpLogOptions.getLogLevel(); if (httpLogLevel.shouldLogUrl()) { logger.info("<-- ({} ms, body)", response.getStatusCode(), url, tookMs, bodySize); } if (httpLogLevel.shouldLogHeaders()) { formatAllowableHeaders(httpLogOptions.getAllowedHeaderNames(), response.getHeaders(), logger); } if (httpLogLevel.shouldLogBody()) { long contentLength = getContentLength(response.getHeaders()); final String contentTypeHeader = response.getHeaderValue("Content-Type"); if (!"application/octet-stream".equalsIgnoreCase(contentTypeHeader) && contentLength != 0 && contentLength < MAX_BODY_LOG_SIZE) { final HttpResponse bufferedResponse = response.buffer(); return bufferedResponse.getBodyAsString().map(bodyStr -> { bodyStr = prettyPrintIfNeeded(logger, contentTypeHeader, bodyStr); logger.info("Response body:\n{}", bodyStr); logger.info("<-- END HTTP"); return bufferedResponse; }).switchIfEmpty(Mono.defer(() -> Mono.just(bufferedResponse))); } else { logger.info("(body content not logged)"); logger.info("<-- END HTTP"); } } else { logger.info("<-- END HTTP"); } return Mono.just(response); }; }