From c1dc1011b3bb9257c4002d9de0ebd40acecb8c43 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:28:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BD=B2=E5=90=8D=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=82=E3=83=AD=E3=82=B0=E3=82=92=E3=81=A8=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ap/APRequestServiceImpl.kt | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APRequestServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APRequestServiceImpl.kt index b8074037..75eb4fa4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APRequestServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APRequestServiceImpl.kt @@ -42,6 +42,7 @@ class APRequestServiceImpl( header("Accept", ContentType.Application.Activity) header("Date", date) }.bodyAsText() + logBody(bodyAsText, url) return objectMapper.readValue(bodyAsText, responseClass) } @@ -81,15 +82,7 @@ class APRequestServiceImpl( httpResponse.status, httpResponse.request.url ) - logger.trace( - """ - |***** BEGIN HTTP Response Trace url: {} ***** - | - |$bodyAsText - | - |***** END HTTP Response TRACE url: {} ***** - """.trimMargin(), url, url - ) + logBody(bodyAsText, url) return readValue } @@ -116,11 +109,13 @@ class APRequestServiceImpl( logger.trace( """ + | |***** BEGIN HTTP Request Trace url: {} ***** | |$requestBody | |***** END HTTP Request Trace url: {} ***** + | """.trimMargin(), url, url ) @@ -131,13 +126,15 @@ class APRequestServiceImpl( val date = dateTimeFormatter.format(ZonedDateTime.now(ZoneId.of("GMT"))) val u = URL(url) if (signer?.privateKey == null) { - return httpClient.post(url) { + val bodyAsText = httpClient.post(url) { header("Accept", ContentType.Application.Activity) header("Date", date) header("Digest", "sha-256=$digest") setBody(requestBody) contentType(ContentType.Application.Activity) }.bodyAsText() + logBody(bodyAsText, url) + return bodyAsText } val headers = headers { @@ -177,16 +174,22 @@ class APRequestServiceImpl( httpResponse.status, httpResponse.request.url ) + logBody(bodyAsText, url) + return bodyAsText + } + + private fun logBody(bodyAsText: String, url: String) { logger.trace( """ - |***** BEGIN HTTP Response Trace url: {} ***** - | - |$bodyAsText - | - |***** END HTTP Response TRACE url: {} ***** - """.trimMargin(), url, url + | + |***** BEGIN HTTP Response Trace url: {} ***** + | + |$bodyAsText + | + |***** END HTTP Response TRACE url: {} ***** + | + """.trimMargin(), url, url ) - return bodyAsText } companion object {