Alexandre Brown
08/23/2021, 12:45 PM@Location
on Ktor 1.6.0, anybody had similar issue?
dependencies {
implementation("io.ktor:ktor-locations:$ktorVersion")
}
tasks.withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs += listOf("-Xuse-experimental=io.ktor.locations.KtorExperimentalLocationsAPI")
}
import io.ktor.locations.Location
@Location("/mylocation")
class MyLocation
fun Application.someFun() {
routing {
route("/my-root") {
post<MyLocation> {
Didier Villevalois
08/23/2021, 1:07 PMktor-network
:
• Why is TcpSocketBuilder.connect(...)
suspending while TcpSocketBuilder.bind(...)
is not ?
• Would it be in the project scope to accept a contribution for a UnixDomainSocketBuilder
?Alexandre Brown
08/23/2021, 5:14 PMException in thread "DefaultDispatcher-worker-2" kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unresolved class: class applications.web.routes.roadclassification.MyLocation
import <http://io.ktor.locations.post|io.ktor.locations.post>
...
fun Routing.myFun() {
route("/my-route") {
post<MyLocation> {
call.respondText { "hello" }
}
}
}
import io.ktor.locations.Location
@Location("/mylocation")
class MyLocation
The app works when not running the native image (regular jar) or when running the native image without using the Location feature.
ThanksJonathan Hollingsworth
08/23/2021, 7:07 PMkotlinx.serializable
On the way out (i.e. serializing) it works fine with this
@Serializable
data class Task(
var id: Int? = null, val title: String, val detail: String? = null,
@Contextual
val dueDate: LocalDate? = null
)
But when I try to
val task = call.receive<Task>()
in route, then I get an Serializer for class 'LocalDate' is not found.
I've been through the kotlinx.serialization docs, but I can't see find anything to help.Piotr Krzemiński
08/24/2021, 6:44 AMhfhbd
08/24/2021, 12:48 PMstreamProvider
only available for PartData.FileItem
and not for all PartData
subclasses? It is only a shortcut for provider().asStream()
https://github.com/ktorio/ktor/blob/1bd92eaa4974dc0b09757c635895ce0e38474a95/ktor-http/jvm/src/io/ktor/http/content/MultipartJvm.ktAndre Stefanov
08/24/2021, 1:50 PMalbrechtroehm
08/24/2021, 4:13 PMCLOVIS
08/25/2021, 2:01 PMStringValuesBuilder.append
has been marked as internal. However, it is necessary to create multipart requests:
builder.append(FormPart(name, data, Headers.build {
append(HttpHeaders.ContentType, mime) // this is now marked as internal
}))
I didn't see anything explaining how we should migrate our code.hfhbd
08/26/2021, 8:11 AMedenman
08/26/2021, 8:25 AMjdoneill
08/26/2021, 5:23 PMktor-auth
dependency setup document for mulitplatform android/ios/web? I am running into this error:
No matching variant of io.ktor:ktor-auth:1.6.3 was found. The consumer was configured to find a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js', attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but:
- Variant 'jvmApiElements-published' capability io.ktor:ktor-auth:1.6.3:
- Incompatible because this component declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
- Other compatible attribute:
- Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
Using Kotlin 1.5.30, Ktor 1.6.3, applying the ktor-auth
in common and mixing in ktor-client-auth-js
in common and/or jsMain and continue to get this error building/running web
This worked with previous versions but having issues getting it to work now on web/js, anyone seen this?Rafał Kuźmiński
08/26/2021, 7:31 PMget("someRoute"){
call.respondFile(someFile)
}
Downloaded file will be named "someRoute". Can I change it?rnett
08/26/2021, 9:50 PMrefreshTokens
) does not seem to have actually made it into the release, see my comment on the issue for detailsDazai
08/28/2021, 1:16 AMJuanDocal
08/30/2021, 5:11 AMMyCodeFlow
08/30/2021, 5:39 AMfun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
fun Application.module(testing: Boolean = false) {
//initialization of the Database
DataBaseFactory.init()
val userDb = UserDataBaseDao() //Users Database
val loveCardDb = LoveCardsDataBaseDao()
val hashFunction = { s: String -> hash(s) }
val jwtService = JwtService()
//installing content receive/respond functionality
install(ContentNegotiation) {
json() //converter for serialization of kotlin classes
}
//installing authentication
install(Authentication){
jwt("jwt") {
verifier(jwtService.varifier)
realm = "Lovecard server"
validate {
val payload = it.payload
val email = payload.getClaim("email").asString()
val user = userDb.findUserByEmail(email)
user
}
}
}
//installing WebSocket
install(WebSockets) {
pingPeriod = Duration.ofSeconds(15)
timeout = Duration.ofSeconds(15)
maxFrameSize = Long.MAX_VALUE
masking = false
}
routing {
//basic route on connection to server
get("/") {
call.respondText("Hello world!", contentType = ContentType.Text.Plain)
}
//echo unit of websocket
webSocket("/echo") {
send("Please enter your name")
for (frame in incoming) {
when (frame) {
is Frame.Text -> {
val receivedText = frame.readText()
if (receivedText.equals("bye", ignoreCase = true)) {
close(CloseReason(CloseReason.Codes.NORMAL, "Client said BYE"))
} else {
send(Frame.Text("Hi, $receivedText!"))
}
}
}
}
}
//Websocket for data exchange
val connections = Collections.synchronizedSet<Connection?>(LinkedHashSet())
webSocket("/connection") {
val thisConnection = Connection(this)
connections += thisConnection
send("You've logged in as [${thisConnection.name}]")
for (frame in incoming) {
when (frame) {
is Frame.Text -> {
val receivedText = frame.readText()
val textWithUsername = "[${thisConnection.name}]: $receivedText"
connections.forEach {
it.session.send(textWithUsername)
}
}
}
}
}
//register Authentication routes
authRouting(hashFunction, jwtService)
//register User routes
userRouting(userDb, jwtService, hashFunction)
//register LoveCards routes
loveCardsRouting(loveCardDb)
}
class Connection(val session: DefaultWebSocketSession) {
companion object{
var lastId = AtomicInteger(0)
}
val name = "User ${lastId.getAndIncrement()}"
}
}
Hien Nguyen
08/30/2021, 7:32 AM<http://httpClient.post|httpClient.post><Unit> {
val bucket = it.fields.bucket
url {
encodedPath = bucket
}
body = MultiPartFormDataContent(
formData {
append("bucket", bucket)
append("Policy", it.fields.policy)
append("X-Amz-Date", it.fields.date)
append("X-Amz-Algorithm", it.fields.algorithm)
append("X-Amz-Signature", it.fields.signature)
append("X-Amz-Security-Token", it.fields.securityToken)
append("X-Amz-Credential", it.fields.credential)
append("acl", it.fields.acl)
append("key", it.fields.key)
appendInput(
key = "file",
headers = Headers.build {
append(HttpHeaders.ContentDisposition, "filename=uuid.jpg")
append(HttpHeaders.ContentType, "image/jpeg")
}) {
buildPacket { writeFully(input.imageByteArray) }
}
}
)
}
but I meet the below error
javax.net.ssl.SSLException: Write error: ssl=0xcbc0b608: I/O error during system call, Broken pipe
😞 If I upload the image to another server (not S3 anymore), the upload is successfully
anyone help me 😞 ?james
08/30/2021, 8:42 AMsuspend fun getAllVenues(lat: Double, lon: Double): VenueResponse {
return client.get(BuildConfig.API_URL + "venues") {
parameter("lat", lat)
parameter("lon", lon)
}
}
single {
HttpClient(Android) {
install(JsonFeature) {
serializer = GsonSerializer {
setPrettyPrinting()
disableHtmlEscaping()
}
}
expectSuccess = false
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
}
}
oletjens
08/30/2021, 1:11 PMchristophsturm
08/31/2021, 8:48 AM<http://ktor.post|ktor.post>(url) {
body = ...
headers {
append("Content-Type", "application/json")
append("Authorization", "Bearer $bearer")
}
“This API is internal in ktor and should not be used. It could be removed or changed without notice.”Michal Harakal
08/31/2021, 9:54 AMSebastian Owodzin
08/31/2021, 1:53 PMExecution failed for task ':app-android:mobile:minifyReleaseWithR8'.
> Could not resolve all files for configuration ':app-android:mobile:releaseRuntimeClasspath'.
> Failed to transform ktor-client-core-jvm-1.6.2.jar (io.ktor:ktor-client-core-jvm:1.6.2) to match attributes {artifactType=android-asm-instrumented-jars, asm-transformed-variant=release, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
> Execution failed for AsmClassesTransform: /Users/sowodzin/.gradle/caches/transforms-3/f7fb63019a1553b70833efe63d6a881f/transformed/jetified-ktor-client-core-jvm-1.6.2.jar.
> Index -1 out of bounds for length 0
Koltin version: 1.5.21
Android Gradle Plugin 7.0.1 (everything is fine when I switch back to 4.1.3)landon burch
08/31/2021, 8:27 PMkeishi kubo
09/01/2021, 3:45 AMPatrick Ramsey
09/01/2021, 6:25 AMshusek
09/01/2021, 9:43 AM<http://io.ktor.utils.io|io.ktor.utils.io>.core.Input
or <http://io.ktor.utils.io|io.ktor.utils.io>.core.Output
? I can't find a description for them and i am affraid it is internal classes which will be deleted.
My problem is that ByteReadChannel is malformed on receive but io.ktor.utils.i.core.Input
works fine. Can i use Input
class without fear?
val channel: Input = httpResponse.receive() //works fine
val channel: ByteReadChannel = httpResponse.receive() // throw exception MalformedInputException: Input length = 1
ptsiogas
09/01/2021, 10:01 AMheader("Cookie", cookie)
but Ktor seems to ignore it.Undervoid
09/02/2021, 7:22 AMfun Application.ktorMain() {
// set up omitted
val root = feature(Routing)
val allRoutes = allRoutes(root)
val allRoutesWithMethod = allRoutes.filter { it.selector is HttpMethodRouteSelector }
allRoutesWithMethod.forEach {
<http://logger.info|logger.info>("route: $it")
}
}
fun allRoutes(root: Route): List<Route> {
return listOf(root) + root.children.flatMap { allRoutes(it) }
}
is there another approach to do it ?Matthieu Stombellini
09/02/2021, 12:31 PMParameters.build
now that StringValuesBuilder
is internal? My use case is sending a request that has application/x-www-form-urlencoded
data. Using this:
FormDataContent(Parameters.build {
append("some", "thing")
})
results in a warning (and an error in my case since I'm using -Werror
) on the append
call.
This API is internal in ktor and should not be used. It could be removed or changed without notice.
This is because StringValuesBuilder
is marked with @InternalAPI
, andd using it is required for doing basically any building for parameters. Is it now impossible to use FormDataContent
without relying on Ktor's internals?Matthieu Stombellini
09/02/2021, 12:31 PMParameters.build
now that StringValuesBuilder
is internal? My use case is sending a request that has application/x-www-form-urlencoded
data. Using this:
FormDataContent(Parameters.build {
append("some", "thing")
})
results in a warning (and an error in my case since I'm using -Werror
) on the append
call.
This API is internal in ktor and should not be used. It could be removed or changed without notice.
This is because StringValuesBuilder
is marked with @InternalAPI
, andd using it is required for doing basically any building for parameters. Is it now impossible to use FormDataContent
without relying on Ktor's internals?Lars Toft Jacobsen
09/02/2021, 1:09 PMFormDataContent
- but anyway it looks like you can use Parameters
factories now i.e. parametersOf()
Aleksei Tirman [JB]
09/02/2021, 2:39 PM@OptIn(InternalAPI::class)
for now. For more information please read https://youtrack.jetbrains.com/issue/KTOR-3001#focus=Comments-27-5105259.0-0.