Skip to content

Commit

Permalink
KTOR-5199 validate actual protocol for upgrade request
Browse files Browse the repository at this point in the history
  • Loading branch information
dtretyakov committed Jan 25, 2024
1 parent 650afdc commit 315079a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Expand Up @@ -43,9 +43,8 @@ internal class CurlProcessor(coroutineContext: CoroutineContext) {
}

suspend fun executeRequest(request: CurlRequestData): CurlSuccess {
if (request.isUpgradeRequest && !curlProtocols.contains("ws")) {
@Suppress("DEPRECATION")
throw CurlRuntimeException("WebSockets are supported in experimental libcurl 7.86 and greater")
if (request.isUpgradeRequest && !curlProtocols.contains(request.protocol)) {
error("WebSockets are supported in experimental libcurl 7.86 and greater")
}

val result = CompletableDeferred<CurlSuccess>()
Expand Down
Expand Up @@ -20,6 +20,7 @@ import kotlin.coroutines.*

@OptIn(ExperimentalForeignApi::class, InternalAPI::class)
internal suspend fun HttpRequestData.toCurlRequest(config: CurlClientEngineConfig): CurlRequestData = CurlRequestData(
protocol = url.protocol.name,
url = url.toString(),
method = method.value,
headers = headersToCurl(),
Expand All @@ -36,6 +37,7 @@ internal suspend fun HttpRequestData.toCurlRequest(config: CurlClientEngineConfi
)

internal class CurlRequestData @OptIn(ExperimentalForeignApi::class) constructor(
val protocol: String,
val url: String,
val method: String,
val headers: CPointer<curl_slist>,
Expand Down

0 comments on commit 315079a

Please sign in to comment.