mirror of https://github.com/usbharu/Hideout.git
feat: ActivityPubリクエストのログを追加
This commit is contained in:
parent
cec0c620f6
commit
94900cc32c
|
@ -34,6 +34,7 @@ class APRequestServiceImpl(
|
||||||
) : APRequestService {
|
) : APRequestService {
|
||||||
|
|
||||||
override suspend fun <R : Object> apGet(url: String, signer: User?, responseClass: Class<R>): R {
|
override suspend fun <R : Object> apGet(url: String, signer: User?, responseClass: Class<R>): R {
|
||||||
|
logger.debug("START ActivityPub Request GET url: {}, signer: {}", url, signer?.url)
|
||||||
val date = dateTimeFormatter.format(ZonedDateTime.now(ZoneId.of("GMT")))
|
val date = dateTimeFormatter.format(ZonedDateTime.now(ZoneId.of("GMT")))
|
||||||
val u = URL(url)
|
val u = URL(url)
|
||||||
if (signer?.privateKey == null) {
|
if (signer?.privateKey == null) {
|
||||||
|
@ -63,7 +64,7 @@ class APRequestServiceImpl(
|
||||||
signHeaders = listOf("(request-target)", "date", "host", "accept")
|
signHeaders = listOf("(request-target)", "date", "host", "accept")
|
||||||
)
|
)
|
||||||
|
|
||||||
val bodyAsText = httpClient.get(url) {
|
val httpResponse = httpClient.get(url) {
|
||||||
headers {
|
headers {
|
||||||
headers {
|
headers {
|
||||||
appendAll(headers)
|
appendAll(headers)
|
||||||
|
@ -72,8 +73,24 @@ class APRequestServiceImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contentType(ContentType.Application.Activity)
|
contentType(ContentType.Application.Activity)
|
||||||
}.bodyAsText()
|
}
|
||||||
return objectMapper.readValue(bodyAsText, responseClass)
|
val bodyAsText = httpResponse.bodyAsText()
|
||||||
|
val readValue = objectMapper.readValue(bodyAsText, responseClass)
|
||||||
|
logger.debug(
|
||||||
|
"SUCCESS ActivityPub Request GET status: {} url: {}",
|
||||||
|
httpResponse.status,
|
||||||
|
httpResponse.request.url
|
||||||
|
)
|
||||||
|
logger.trace(
|
||||||
|
"""
|
||||||
|
|***** BEGIN HTTP Response Trace url: {} *****
|
||||||
|
|
|
||||||
|
|$bodyAsText
|
||||||
|
|
|
||||||
|
|***** END HTTP Response TRACE url: {} *****
|
||||||
|
""".trimMargin(), url, url
|
||||||
|
)
|
||||||
|
return readValue
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun <T : Object, R : Object> apPost(
|
override suspend fun <T : Object, R : Object> apPost(
|
||||||
|
@ -87,6 +104,7 @@ class APRequestServiceImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun <T : Object> apPost(url: String, body: T?, signer: User?): String {
|
override suspend fun <T : Object> apPost(url: String, body: T?, signer: User?): String {
|
||||||
|
logger.debug("START ActivityPub Request POST url: {}, signer: {}", url, signer?.url)
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
val mutableListOf = mutableListOf<String>()
|
val mutableListOf = mutableListOf<String>()
|
||||||
mutableListOf.add("https://www.w3.org/ns/activitystreams")
|
mutableListOf.add("https://www.w3.org/ns/activitystreams")
|
||||||
|
@ -96,6 +114,16 @@ class APRequestServiceImpl(
|
||||||
|
|
||||||
val requestBody = objectMapper.writeValueAsString(body)
|
val requestBody = objectMapper.writeValueAsString(body)
|
||||||
|
|
||||||
|
logger.trace(
|
||||||
|
"""
|
||||||
|
|***** BEGIN HTTP Request Trace url: {} *****
|
||||||
|
|
|
||||||
|
|$requestBody
|
||||||
|
|
|
||||||
|
|***** END HTTP Request Trace url: {} *****
|
||||||
|
""".trimMargin(), url, url
|
||||||
|
)
|
||||||
|
|
||||||
val sha256 = MessageDigest.getInstance("SHA-256")
|
val sha256 = MessageDigest.getInstance("SHA-256")
|
||||||
|
|
||||||
val digest = Base64Util.encode(sha256.digest(requestBody.toByteArray()))
|
val digest = Base64Util.encode(sha256.digest(requestBody.toByteArray()))
|
||||||
|
@ -103,8 +131,6 @@ class APRequestServiceImpl(
|
||||||
val date = dateTimeFormatter.format(ZonedDateTime.now(ZoneId.of("GMT")))
|
val date = dateTimeFormatter.format(ZonedDateTime.now(ZoneId.of("GMT")))
|
||||||
val u = URL(url)
|
val u = URL(url)
|
||||||
if (signer?.privateKey == null) {
|
if (signer?.privateKey == null) {
|
||||||
logger.debug("NOT SIGN Request: {}", url)
|
|
||||||
logger.trace("{}", signer)
|
|
||||||
return httpClient.post(url) {
|
return httpClient.post(url) {
|
||||||
header("Accept", ContentType.Application.Activity)
|
header("Accept", ContentType.Application.Activity)
|
||||||
header("Date", date)
|
header("Date", date)
|
||||||
|
@ -114,8 +140,6 @@ class APRequestServiceImpl(
|
||||||
}.bodyAsText()
|
}.bodyAsText()
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("SIGN Request: {}", url)
|
|
||||||
|
|
||||||
val headers = headers {
|
val headers = headers {
|
||||||
append("Accept", ContentType.Application.Activity)
|
append("Accept", ContentType.Application.Activity)
|
||||||
append("Date", date)
|
append("Date", date)
|
||||||
|
@ -136,7 +160,7 @@ class APRequestServiceImpl(
|
||||||
signHeaders = listOf("(request-target)", "date", "host", "digest")
|
signHeaders = listOf("(request-target)", "date", "host", "digest")
|
||||||
)
|
)
|
||||||
|
|
||||||
return httpClient.post(url) {
|
val httpResponse = httpClient.post(url) {
|
||||||
headers {
|
headers {
|
||||||
headers {
|
headers {
|
||||||
appendAll(headers)
|
appendAll(headers)
|
||||||
|
@ -146,7 +170,23 @@ class APRequestServiceImpl(
|
||||||
}
|
}
|
||||||
setBody(requestBody)
|
setBody(requestBody)
|
||||||
contentType(ContentType.Application.Activity)
|
contentType(ContentType.Application.Activity)
|
||||||
}.bodyAsText()
|
}
|
||||||
|
val bodyAsText = httpResponse.bodyAsText()
|
||||||
|
logger.debug(
|
||||||
|
"SUCCESS ActivityPub Request POST status: {} url: {}",
|
||||||
|
httpResponse.status,
|
||||||
|
httpResponse.request.url
|
||||||
|
)
|
||||||
|
logger.trace(
|
||||||
|
"""
|
||||||
|
|***** BEGIN HTTP Response Trace url: {} *****
|
||||||
|
|
|
||||||
|
|$bodyAsText
|
||||||
|
|
|
||||||
|
|***** END HTTP Response TRACE url: {} *****
|
||||||
|
""".trimMargin(), url, url
|
||||||
|
)
|
||||||
|
return bodyAsText
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
Loading…
Reference in New Issue