Skip to content

Commit

Permalink
KTOR-3566 Fixed sending DELETE with body in Curl engine (#3165)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsinukov committed Sep 26, 2022
1 parent 4ab5d7b commit 24d59f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/test/server/ClientTestServer.kt
Expand Up @@ -69,6 +69,9 @@ internal fun Application.tests() {
val contentType = call.request.header(HttpHeaders.ContentType)
call.respondText(contentType ?: "")
}
delete("/delete") {
call.respondText("OK ${call.receiveText()}")
}
}
}

Expand Down
Expand Up @@ -155,15 +155,16 @@ internal class CurlMultiApiHandler : Closeable {
easyHandle.apply {
when (method) {
"GET" -> option(CURLOPT_HTTPGET, 1L)
"PUT" -> {
option(CURLOPT_PUT, 1L)
}
"PUT" -> option(CURLOPT_PUT, 1L)
"POST" -> {
option(CURLOPT_POST, 1L)
option(CURLOPT_POSTFIELDSIZE, size)
}
"HEAD" -> option(CURLOPT_NOBODY, 1L)
else -> option(CURLOPT_CUSTOMREQUEST, method)
else -> {
if (size > 0) option(CURLOPT_POST, 1L)
option(CURLOPT_CUSTOMREQUEST, method)
}
}
}
}
Expand Down
Expand Up @@ -8,31 +8,34 @@ import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.curl.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.utils.io.core.*
import kotlinx.coroutines.*
import kotlin.native.concurrent.*
import kotlin.test.*

val backgroundWorker = Worker.start()

class CurlNativeTests {

private val TEST_SERVER: String = "http://127.0.0.1:8080"

@Test
@Ignore
fun testDownloadInBackground() {
backgroundWorker.execute(TransferMode.SAFE, { Unit }) {
runBlocking {
val client = HttpClient(Curl)
client.get("http://google.com").body<String>()
}
}.consume { assert(it.isNotEmpty()) }
fun testDownload() = runBlocking {
HttpClient(Curl).use {
val res = it.get("http://google.com").body<String>()
assert(res.isNotEmpty())
}
}

@Test
fun testDownload() {
runBlocking {
val client = HttpClient(Curl)
val res = client.get("http://google.com").body<String>()
assert(res.isNotEmpty())
fun testDelete(): Unit = runBlocking {
HttpClient(Curl).use {
val response = it.delete("$TEST_SERVER/delete")
assertEquals("OK ", response.bodyAsText())

val responseWithBody = it.delete("$TEST_SERVER/delete") {
setBody("1")
}
assertEquals("OK 1", responseWithBody.bodyAsText())
}
}
}

0 comments on commit 24d59f0

Please sign in to comment.