kotlin - 如何增加 ktor 可接受 url 的最大长度?
问题描述
现在我的ktor服务器是基于netty的。当我做长 GET 请求(大约 9300 个字符(主要在查询参数中))时,ktor 回答Unhandled: GET - /bad-request
。如果我减少 url 的长度,它工作正常。
解决方案
在您的嵌入式服务器配置中,您可以提供一个函数“httpServerCodec”来创建 HttpServerCodec ( https://netty.io/4.1/api/io/netty/handler/codec/http/HttpServerCodec.html ),您可以在其中设置 maxInitialLineLength财产。
embeddedServer(Netty, configure = {
// Size of the queue to store [ApplicationCall] instances that cannot be immediately processed
requestQueueLimit = 16
// Do not create separate call event group and reuse worker group for processing calls
shareWorkGroup = false
// User-provided function to configure Netty's [ServerBootstrap]
configureBootstrap = {
// ...
}
httpServerCodec = {
HttpServerCodec(.......)
}
// Timeout in seconds for sending responses to client
responseWriteTimeoutSeconds = 10
}) {
// ...
}.start(true)
推荐阅读
- python - 如何遍历 Pandas DataFrame 并在它们上运行函数
- java - 无法在java中使用“File.copy”方法复制文件
- javascript - 列出多种语言字幕 video.js
- c++ - 检查是否已将指针设置为已初始化的对象
- sql - 从 Bigquery 中的原始表主动创建洞察表
- javascript - 在单独的列中触发内容更改?
- php - 尝试在服务器上下载文件时,file_get_contents 不适用于某些 url
- java - 如何在 Userexit 类 Maximo 中获取 ER 数据中的当前 mbo
- css - flexbox启用元素中的overflow-x不允许滚动
- mysql - Docker Compose:无法连接到我的 MySQL 容器