xxfast
02/04/2022, 2:20 AMСтефан Јовановић
02/04/2022, 8:15 AMauthenticate("auth-session") {}
Joris PZ
02/04/2022, 9:00 AMFoo
to run after the existing Authentication
plugin. When I try
val Foo = createApplicationPlugin("Foo") {
after(Authentication) {
}
}
the line starting with after
generates a compiler error:
Type mismatch.
Required: io.ktor.server.application.Plugin<*, *, PluginInstance>
Found: io.ktor.server.auth.Authentication.Plugin
The supertype of io.ktor.server.auth.Authentication.Plugin
is ApplicationPlugin<Application, Configuration, Authentication>
. Now I am not strong on generics, but I guess this is indeed not a subtype of the required io.ktor.server.application.Plugin<*, *, PluginInstance>
(Is this the same issue as you talk about here, @hhariri?)
Is there any way to make my plugin run after the Authentication plugin?Mitchel Nijdam
02/04/2022, 11:56 AMLukasz Kalnik
02/04/2022, 11:58 PMdefaultRequest
seems not to work anymore:
HttpClient {
// ...
defaultRequest {
url {
protocol = URLProtocol.HTTPS
host = "<http://api.themoviedb.org|api.themoviedb.org>"
encodedPath = "/3$encodedPath" // prepend API version to path
parametersOf("api_key", "my_api_key_value")
}
}
}
suspend fun getConfiguration(): ApiConfig = client.get("configuration").body()
produces:
io.ktor.client.plugins.ClientRequestException: Client request(GET <https://api.themoviedb.org/3/configuration>) invalid: 401 Unauthorized. Text: "{"status_code":7,"status_message":"Invalid API key: You must be granted a valid key.","success":false}
SooYoung
02/05/2022, 2:10 AM2.0.0-beta-1
.jw
02/05/2022, 4:02 AMjw
02/05/2022, 4:10 AMLandry Norris
02/05/2022, 8:07 PMandylamax
02/06/2022, 11:28 AMio.ktor:server-cors
Apart from that, I haven't come across any hardships really in the whole migration process, process took approximate 20 minutes. Taking into account that this was a multiplatform project with ktor both on the server and client side.
Anyone who was skeptical migrating to it, should not be worried at allOvsyannikov Alexey
02/07/2022, 3:31 PMwindow.fetch
, but I didn't found any way in ktor to upload files as streamsJohnny Baloney
02/07/2022, 4:22 PMKtor now supports a way to construct a JSON body using theDSL:kotlinx.serialization
<http://client.post|client.post>("<http://localhost:9090>") {
contentType(ContentType.Application.Json)
body = json {
"key1" to 123
"map" to json {
"key2" to "abc"
}
}
}
To use it on a client, install JsonFeature and add the ktor-client-serialization dependency.When I paste this into the editor
json
function is not recognised. How do I enable the kotlinx.serialization DSL?cafonsomota
02/08/2022, 3:42 PMdimsuz
02/08/2022, 4:25 PM1.6.10
and kotlin-native (iOS), whenever default logger
is installed on HttpClient, it fails some responses with
Is there a workaround for this? Removing httpFail to create response observer in different native thread.
logger
fixes this, seems like some internal ktor bug.calrissian
02/08/2022, 11:56 PMByteZ
02/09/2022, 3:23 PMX-GitHub-Event
but the server receives X-Github-Event
with a lower case h. I've contacted GitHub support and they said it's caused by the receiving server. If it Is caused by ktor, is there a way to keep the original names?Lucas
02/10/2022, 5:12 PMJavier
02/10/2022, 10:04 PMjava.nio.channels.UnresolvedAddressException
) in my custom plugin, in which phase should I do that?Tunji Dahunsi
02/10/2022, 11:05 PM[ModelValidationHandler, AuthErrorHandler]
and so on.
Similar to the Logging
feature, I’ve implemented my handlers as HttpClientFeature<*, *>
. The issue I’m having is once one of my handlers reads the content
ByteReadChannel
of the HttpResponse
as a String
, the channel is fully read, and no other Handler can read it.
I read the response like this:
val observer: ResponseHandler = { response ->
try {
val message = response.content
.readRemaining()
.readText(charset = response.charset()?: Charsets.UTF_8)
} catch (_: Throwable) {
}
}
ResponseObserver.install(ResponseObserver(observer), scope)
The Logging
feature does not have this limitation. It can log the response, and I can still read it once. Am I consuming the wrong response?Leonid Golberg
02/11/2022, 9:34 AMCoroutines must be initialized from the main thread: call 'initMainThread' from the main thread first
?
I am launching raw socket API on iOS, ktor version 2.0.0-beta-1
Piotr Prus
02/11/2022, 5:04 PMmichaelv
02/12/2022, 1:02 AMinstall(StatusPages) {
exception<Throwable> { cause ->
call.respond(HttpStatusCode.InternalServerError)
}
}
But if I use 2.0.0-beta-1 instead of 2.0.0-eap-256 then it complains like this. Anyone else seeing that? I did a search and didn’t see anyone post about it yet.
https://ktor.io/docs/status-pages.html#exceptionsJúlio Santos
02/12/2022, 2:41 AMLastExceed
02/12/2022, 7:31 AM.close
.awaitClose()
and .dispose()
but as long as the program is running it's not letting any other programs listen on that portStephan Schroeder
02/12/2022, 8:54 PMfun main() {
embeddedServer(Netty, port = 8080, host = "localhost") {
configureRouting()
configureSerialization()
}.start(wait = true)
}
fun Application.configureSerialization() {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
})
}
}
fun Application.configureRouting() {
routing {
get("/") {
call.respondText("Wolt Opening Times Formatter")
}
post("/") {
val data = call.receive<String>()
call.respondText(data.toString())
}
}
}
so the GET works and POSTing a String works as well, but as soon as I try to parse into something more ambicious, this fails, e.g. let's update the POST like this
post("/") {
val data = call.receive<TestData>()
call.respondText(data.toString())
}
}
}
@kotlinx.serialization.Serializable
data class TestData(
val monday: Int,
)
then sending over this json
{
"monday": 12
}
fails with
Cannot transform this request's content to simonvoid.gmx.de.time_formatter.plugins.TestData
io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to simonvoid.gmx.de.time_formatter.plugins.TestData`
...
Caused by: io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to simonvoid.gmx.de.time_formatter.plugins.TestData
it's the same exception when I try to receive into a Map (val data = call.receive<Map<String,Int>>()
).
Caused by: io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to kotlin.collections.Map<kotlin.String, kotlin.Int>
alightgoesout
02/14/2022, 1:11 PMLandry Norris
02/14/2022, 10:30 PMLucas León
02/15/2022, 5:23 AM@SpringBootApplication
class TodoConsumerApplication {
@Bean
fun httpClient() = HttpClient {
install(JsonFeature)
}
}
fun main(args: Array<String>) {
runApplication<TodoConsumerApplication>(*args)
}
@Service
class TodoConsumerService(
private val httpClient: HttpClient
) {
suspend fun getItemsTwoTimes() {
val result1 = httpClient.get<String>("<http://localhost:8080/items>")
val result2 = httpClient.get<String>("<http://localhost:8080/items>")
println("Result 1 = $result1 and Result 2 = $result2")
}
}
@ExtendWith(SpringExtension::class)
@SpringBootTest
internal class TodoConsumerServiceTest {
@MockkBean
private lateinit var httpClient: HttpClient
@Autowired
private lateinit var todoConsumerService: TodoConsumerService
@Test
fun getItemsTwoTimes() = runBlocking {
}
}
I want to mock two different responses in the service using MockEngineKedar
02/15/2022, 1:59 PMKarl Azzam
02/15/2022, 10:15 PMKarl Azzam
02/15/2022, 10:15 PMBig Chungus
02/15/2022, 10:17 PMKarl Azzam
02/15/2022, 10:21 PMLandry Norris
02/15/2022, 10:37 PMKarl Azzam
02/15/2022, 10:45 PMLandry Norris
02/15/2022, 10:52 PMKarl Azzam
02/15/2022, 10:55 PMLandry Norris
02/15/2022, 10:56 PMKarl Azzam
02/15/2022, 11:00 PM