Skip to content

Commit

Permalink
fix: explicitly remove Content-Type header when making RSocket requests
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed Nov 1, 2023
1 parent 1576711 commit 7ea715b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public class KtorMeetacyEngine(
json(json)
}
defaultRequest {
println("ca62: ${url.protocol}: isWebsocket = ${url.protocol.isWebsocket()}")
if (!url.protocol.isWebsocket()) {
header(HttpHeaders.ContentType, ContentType.Application.Json)
}
header(HttpHeaders.ContentType, ContentType.Application.Json)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import app.meetacy.sdk.engine.ktor.response.ServerResponse
import app.meetacy.sdk.exception.MeetacyConnectionException
import app.meetacy.sdk.exception.MeetacyInternalException
import app.meetacy.sdk.exception.meetacyApiError
import io.ktor.client.*
import io.ktor.http.*
import io.ktor.utils.io.errors.*
import io.rsocket.kotlin.RSocket
import io.rsocket.kotlin.RSocketError
import io.rsocket.kotlin.ktor.client.rSocket
import kotlinx.coroutines.CancellationException
import kotlinx.serialization.json.Json

Expand Down Expand Up @@ -37,3 +41,15 @@ internal inline fun <T> handleRSocketExceptions(
}
}
}

internal suspend fun HttpClient.meetacyRSocket(
urlString: String,
secure: Boolean
): RSocket {
return rSocket(
urlString = urlString,
secure = secure
) {
headers.remove(HttpHeaders.ContentType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package app.meetacy.sdk.engine.ktor.requests.friends

import app.meetacy.sdk.engine.ktor.apiVersion
import app.meetacy.sdk.engine.ktor.handleRSocketExceptions
import app.meetacy.sdk.engine.ktor.meetacyRSocket
import app.meetacy.sdk.engine.ktor.response.ListFriendsResponse
import app.meetacy.sdk.engine.ktor.response.StatusTrueResponse
import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess
Expand Down Expand Up @@ -109,7 +110,7 @@ internal class FriendsEngine(
suspend fun streamFriendsLocation(request: EmitFriendsLocationRequest) = handleRSocketExceptions(json) {
val url = baseUrl.replaceProtocolWithWebsocket() / "location" / "stream"

val socket = httpClient.rSocket(
val socket = httpClient.meetacyRSocket(
urlString = url.string,
secure = url.protocol.isWss
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.meetacy.sdk.engine.ktor.requests.updates

import app.meetacy.sdk.engine.ktor.handleRSocketExceptions
import app.meetacy.sdk.engine.ktor.meetacyRSocket
import app.meetacy.sdk.engine.requests.EmitUpdatesRequest
import app.meetacy.sdk.types.serializable.notification.NotificationSerializable
import app.meetacy.sdk.types.serializable.notification.type
Expand Down Expand Up @@ -29,7 +30,7 @@ internal class UpdatesEngine(
suspend fun stream(request: EmitUpdatesRequest) = handleRSocketExceptions(json) {
val url = baseUrl.replaceProtocolWithWebsocket() / "updates" / "stream"

val socket = httpClient.rSocket(
val socket = httpClient.meetacyRSocket(
urlString = url.string,
secure = url.protocol.isWss
)
Expand Down

0 comments on commit 7ea715b

Please sign in to comment.