Skip to content

Commit

Permalink
Merge pull request #85 from kuzzleio/fix/headers-format
Browse files Browse the repository at this point in the history
fix: headers format in response
  • Loading branch information
OlivierCavadenti authored Jan 18, 2023
2 parents ca02e63 + 4ea6df4 commit 942a183
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/main/kotlin/io/kuzzle/sdk/Kuzzle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ open class Kuzzle {
response.requestId = eventRequestId
response.status = event.status
if (event.headers != null) {
response.headers = event.headers as Map<String?, Any?>
response.headers = event.getHeadersMap() as Map<String?, Any?>?
if (response.headers!!.containsKey("X-Kuzzle-Volatile")) {
response.Volatile = response.headers!!["X-Kuzzle-Volatile"] as Map<String?, Any?>?
}
Expand All @@ -103,11 +103,13 @@ open class Kuzzle {
response.index = event.payload["index"] as String?
response.collection = event.payload["collection"] as String?
} else {
if (! jsonObject.containsKey("headers") && event.headers != null) {
jsonObject = jsonObject.plus("headers" to event.headers)
val jsonObjectEventHeaders = jsonObject.toMutableMap()
if (event.headers != null) {
jsonObjectEventHeaders["headers"] = event.getHeadersMap()
}

response.apply {
fromMap(jsonObject)
fromMap(jsonObjectEventHeaders)
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/main/kotlin/io/kuzzle/sdk/events/MessageReceivedEvent.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package io.kuzzle.sdk.events

import io.ktor.http.*

data class MessageReceivedEvent(
var message: String?,
var payload: Map<String?, Any?> = emptyMap(),
var status: Int = 200,
var headers: Map<String, List<String>>? = null
)
var headers: Headers? = null
) {
fun getHeadersMap(): Map<String, String> {
if (headers == null) {
return emptyMap()
}
return headers!!.entries().associate { it.key to it.value.first() }
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/io/kuzzle/sdk/protocol/Http.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ open class Http : AbstractProtocol {
response.receive(),
payload,
response.status.value,
response.headers.toMap()
response.headers
)
)
} catch (e: Exception) {
Expand Down Expand Up @@ -266,7 +266,7 @@ open class Http : AbstractProtocol {
response.receive(),
payload,
response.status.value,
response.headers.toMap()
response.headers
)
)
} catch (e: Exception) {
Expand Down

0 comments on commit 942a183

Please sign in to comment.