akka-http - 如何停止 akka http 服务器添加默认的 Content-type Header?
问题描述
我正在尝试处理我的一条路由中的请求,如果我没有在请求中传递任何Content-type默认情况下,akka 会将其设置为application/octet-stream。请在下面找到我的实现 -
import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import scala.io.StdIn
object HttpServerContentTypeTest {
def main(args: Array[String]): Unit = {
implicit val actorSystem = ActorSystem(Behaviors.empty, "RandomNumbers")
implicit val executionContext = actorSystem.executionContext
val route = path("proxy"){
Route { context =>
println(context.request.entity.contentType)
context.complete(HttpEntity(ContentTypes.`text/plain(UTF-8)`, ""))
}
}
val bindingFuture = Http().newServerAt("localhost", 9000).bind(route)
// press any key to stop the server
StdIn.readLine()
bindingFuture.flatMap(_.unbind()).onComplete(_ => actorSystem.terminate())
}
}
我通过 Postman 进行了测试(请找到显示标题和使用的正文的屏幕截图)。我正在尝试发送带有非空请求正文的发布请求。另外我没有设置内容类型标题。我希望 akka-http 服务器内部不设置标头Content-type。有没有办法禁用这种默认行为?
解决方案
推荐阅读
- python - 如何解决(settingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.)?
- json - Laravel:从相关表中获取数据(json数组列)
- java - 在二叉搜索树中找到第 k 个最小的元素
- python - 如何使用 Python 在网站链接中使用变量?
- javascript - 如果其他输入文本没有焦点并且具有价值但如果我集中并输入文本仍然存在,如何删除文本
- rust - 有没有办法在运行时指定要进行 serde 的字段名称?
- c++ - 如何工作:排序函数的第三个参数。[arr],[]
- tensorflow - Keras 中以张量流为后端的正则化自定义损失函数
- mysql - 意外删除 MySQL 的“performance_schema”
- html - WooCommerce 订单完成列表样式