@@ -28,30 +28,25 @@ class DHttpClientRequest implements HttpClientRequest, HttpClientResponse {
2828 private static final String CONTENT_ENCODING = "Content-Encoding" ;
2929
3030 private final DHttpClientContext context ;
31-
3231 private final UrlBuilder url ;
33-
3432 private Duration requestTimeout ;
35-
3633 private boolean gzip ;
3734
3835 private BodyContent encodedRequestBody ;
39-
4036 private HttpRequest .BodyPublisher body ;
37+ private String rawRequestBody ;
4138
4239 private HttpRequest .Builder httpRequest ;
4340
4441 private Map <String , List <String >> formParams ;
45-
4642 private Map <String , List <String >> headers ;
4743
4844 private boolean bodyFormEncoded ;
49-
5045 private long requestTimeNanos ;
5146
5247 private HttpResponse <?> httpResponse ;
53-
5448 private BodyContent encodedResponseBody ;
49+ private boolean loggableResponseBody ;
5550
5651 public DHttpClientRequest (DHttpClientContext context , Duration requestTimeout ) {
5752 this .context = context ;
@@ -127,6 +122,7 @@ public HttpClientRequest body(Object bean) {
127122
128123 @ Override
129124 public HttpClientRequest body (String body ) {
125+ this .rawRequestBody = body ;
130126 this .body = HttpRequest .BodyPublishers .ofString (body );
131127 return this ;
132128 }
@@ -292,6 +288,7 @@ public HttpResponse<byte[]> asByteArray() {
292288
293289 @ Override
294290 public HttpResponse <String > asString () {
291+ loggableResponseBody = true ;
295292 return withResponseHandler (HttpResponse .BodyHandlers .ofString ());
296293 }
297294
@@ -381,11 +378,11 @@ public HttpRequest request() {
381378 public String requestBody () {
382379 if (encodedRequestBody != null ) {
383380 return new String (encodedRequestBody .content (), StandardCharsets .UTF_8 );
384- }
385- if (bodyFormEncoded ) {
381+ } else if (bodyFormEncoded ) {
386382 return buildEncodedFormContent ();
387- }
388- if (body != null ) {
383+ } else if (rawRequestBody != null ) {
384+ return rawRequestBody ;
385+ } else if (body != null ) {
389386 return body .toString ();
390387 }
391388 return null ;
@@ -395,6 +392,12 @@ public String requestBody() {
395392 public String responseBody () {
396393 if (encodedResponseBody != null ) {
397394 return new String (encodedResponseBody .content (), StandardCharsets .UTF_8 );
395+ } else if (httpResponse != null && loggableResponseBody ) {
396+ String strBody = httpResponse .body ().toString ();
397+ if (strBody .length () > 1_000 ) {
398+ return strBody .substring (0 , 1_000 ) + "..." ;
399+ }
400+ return strBody ;
398401 }
399402 return null ;
400403 }
0 commit comments