1717package org .springframework .web .reactive .function .client ;
1818
1919import java .net .InetSocketAddress ;
20+ import java .net .URI ;
2021import java .nio .charset .StandardCharsets ;
2122import java .util .List ;
2223import java .util .Map ;
3435import org .springframework .core .io .buffer .DataBuffer ;
3536import org .springframework .core .io .buffer .DefaultDataBufferFactory ;
3637import org .springframework .http .HttpHeaders ;
38+ import org .springframework .http .HttpMethod ;
3739import org .springframework .http .HttpRange ;
40+ import org .springframework .http .HttpRequest ;
3841import org .springframework .http .HttpStatus ;
3942import org .springframework .http .HttpStatusCode ;
4043import org .springframework .http .MediaType ;
4346import org .springframework .http .client .reactive .ClientHttpResponse ;
4447import org .springframework .http .codec .DecoderHttpMessageReader ;
4548import org .springframework .http .codec .json .Jackson2JsonDecoder ;
49+ import org .springframework .lang .Nullable ;
4650import org .springframework .util .LinkedMultiValueMap ;
4751import org .springframework .util .MultiValueMap ;
4852
@@ -67,13 +71,16 @@ class DefaultClientResponseTests {
6771
6872 private final ExchangeStrategies mockExchangeStrategies = mock ();
6973
74+ @ Nullable
75+ private HttpRequest httpRequest = null ;
76+
7077 private DefaultClientResponse defaultClientResponse ;
7178
7279
7380 @ BeforeEach
7481 void configureMocks () {
7582 given (mockResponse .getHeaders ()).willReturn (this .httpHeaders );
76- defaultClientResponse = new DefaultClientResponse (mockResponse , mockExchangeStrategies , "" , "" , () -> null );
83+ defaultClientResponse = new DefaultClientResponse (mockResponse , mockExchangeStrategies , "" , "" , () -> httpRequest );
7784 }
7885
7986
@@ -302,13 +309,30 @@ void createException() {
302309 given (mockResponse .getStatusCode ()).willReturn (HttpStatus .NOT_FOUND );
303310 given (mockResponse .getBody ()).willReturn (Flux .just (dataBuffer ));
304311
312+ httpRequest = new HttpRequest () {
313+ @ Override
314+ public HttpMethod getMethod () {
315+ return HttpMethod .valueOf ("UNKNOWN" );
316+ }
317+
318+ @ Override
319+ public URI getURI () {
320+ return URI .
create (
"https://user:[email protected] :9999/app/path?token=secret#fragment" );
321+ }
322+
323+ @ Override
324+ public HttpHeaders getHeaders () {
325+ return HttpHeaders .EMPTY ;
326+ }
327+ };
328+
305329 given (mockExchangeStrategies .messageReaders ()).willReturn (
306330 List .of (new DecoderHttpMessageReader <>(new ByteArrayDecoder ())));
307331
308332 Mono <WebClientResponseException > resultMono = defaultClientResponse .createException ();
309333 WebClientResponseException exception = resultMono .block ();
310334 assertThat (exception .getStatusCode ()).isEqualTo (HttpStatus .NOT_FOUND );
311- assertThat (exception .getMessage ()).isEqualTo ("404 Not Found" );
335+ assertThat (exception .getMessage ()).isEqualTo ("404 Not Found from UNKNOWN https://example.org:9999/app/path " );
312336 assertThat (exception .getHeaders ()).containsExactly (entry ("Content-Type" , List .of ("text/plain" )));
313337 assertThat (exception .getResponseBodyAsByteArray ()).isEqualTo (bytes );
314338 }
0 commit comments