mirror of https://github.com/usbharu/Hideout.git
fix: apPost時にbodyがnullのときリクエストボディにnullと出力されてしまう問題を修正
This commit is contained in:
parent
dbfc4ed1a7
commit
1eabe75cd9
|
@ -98,14 +98,17 @@ 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)
|
logger.debug("START ActivityPub Request POST url: {}, signer: {}", url, signer?.url)
|
||||||
if (body != null) {
|
val requestBody = 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")
|
||||||
mutableListOf.addAll(body.context)
|
mutableListOf.addAll(body.context)
|
||||||
body.context = mutableListOf
|
body.context = mutableListOf
|
||||||
|
objectMapper.writeValueAsString(body)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
val requestBody = objectMapper.writeValueAsString(body)
|
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"""
|
"""
|
||||||
|
@ -123,17 +126,19 @@ class APRequestServiceImpl(
|
||||||
|
|
||||||
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.orEmpty().toByteArray()))
|
||||||
|
|
||||||
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) {
|
||||||
val bodyAsText = httpClient.post(url) {
|
val bodyAsText = httpClient.post(url) {
|
||||||
header("Accept", ContentType.Application.Activity)
|
accept(ContentType.Application.Activity)
|
||||||
header("Date", date)
|
header("Date", date)
|
||||||
header("Digest", "sha-256=$digest")
|
header("Digest", "sha-256=$digest")
|
||||||
setBody(requestBody)
|
if (requestBody != null) {
|
||||||
contentType(ContentType.Application.Activity)
|
setBody(requestBody)
|
||||||
|
contentType(ContentType.Application.Activity)
|
||||||
|
}
|
||||||
}.bodyAsText()
|
}.bodyAsText()
|
||||||
logBody(bodyAsText, url)
|
logBody(bodyAsText, url)
|
||||||
return bodyAsText
|
return bodyAsText
|
||||||
|
|
Loading…
Reference in New Issue