Expose id from ClientHttpResponse
Closes gh-26656
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -98,14 +98,14 @@ public abstract class ExchangeFunctions {
|
||||
Assert.notNull(clientRequest, "ClientRequest must not be null");
|
||||
HttpMethod httpMethod = clientRequest.method();
|
||||
URI url = clientRequest.url();
|
||||
String logPrefix = clientRequest.logPrefix();
|
||||
|
||||
return this.connector
|
||||
.connect(httpMethod, url, httpRequest -> clientRequest.writeTo(httpRequest, this.strategies))
|
||||
.doOnRequest(n -> logRequest(clientRequest))
|
||||
.doOnCancel(() -> logger.debug(logPrefix + "Cancel signal (to close connection)"))
|
||||
.doOnCancel(() -> logger.debug(clientRequest.logPrefix() + "Cancel signal (to close connection)"))
|
||||
.onErrorResume(WebClientUtils.WRAP_EXCEPTION_PREDICATE, t -> wrapException(t, clientRequest))
|
||||
.map(httpResponse -> {
|
||||
String logPrefix = getLogPrefix(clientRequest, httpResponse);
|
||||
logResponse(httpResponse, logPrefix);
|
||||
return new DefaultClientResponse(
|
||||
httpResponse, this.strategies, logPrefix, httpMethod.name() + " " + url,
|
||||
@@ -120,6 +120,10 @@ public abstract class ExchangeFunctions {
|
||||
);
|
||||
}
|
||||
|
||||
private String getLogPrefix(ClientRequest request, ClientHttpResponse response) {
|
||||
return request.logPrefix() + "[" + response.getId() + "] ";
|
||||
}
|
||||
|
||||
private void logResponse(ClientHttpResponse response, String logPrefix) {
|
||||
LogFormatUtils.traceDebug(logger, traceOn -> {
|
||||
int code = response.getRawStatusCode();
|
||||
|
||||
Reference in New Issue
Block a user