简体   繁体   English

Akka-http非法请求标头

[英]Akka-http illegal request header

I have exposed a simple endpoint that takes in two query parameters. 我公开了一个简单的终结点,该终结点包含两个查询参数。 When I test the code locally I don't have any problems. 当我在本地测试代码时,我没有任何问题。 But when deployed to prod I see the following message: 但是当部署到产品时,我会看到以下消息:

a.a.ActorSystemImpl Illegal request header: Illegal 'cookie' header: Invalid input '/', expected tchar, '\r', WSP or '=' (line 1, column 186): ...

As you can see I'm not doing any cookie parsing 如您所见,我没有进行任何Cookie解析

import akka.actor.{ActorSystem, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Sink

object MainApp extends App {
  implicit val system = ActorSystem()
  implicit val materializer = ActorMaterializer()

  private val config = system.settings.config

  private val server = Http().bind(config.getString("akka.http.server.interface"), config.getInt("akka.http.server.port"))

  private val route = {
    path("replay") {
      get {
        parameters("fromDate", "toDate") { (fromDate, toDate) =>
          complete {
            <some other code>
          }
        }
      }
    }
  }

  val bindingFuture = server.to(Sink.foreach {
    connection =>
      connection handleWith route
  }).run()
}

Any suggestions would be appreciated! 任何建议,将不胜感激!

You are getting an illegal request header exception, so whatever is calling your endpoint (making the request) is passing you that illegal Cookie header value. 您将收到一个非法的请求标头异常,因此调用端点(发出请求)的任何人都将非法的Cookie标头值传递给您。 It has nothing to do with this request handling code. 它与此请求处理代码无关。 Simply put, "It's not you, it's them". 简而言之,“不是你,是他们”。

As long as the request itself is valid (aside from this bad header), then processing should continue (it's non-terminal). 只要请求本身是有效的(除了这个错误的头),那么处理就应该继续(它是非终止的)。 You can try and figure out what's calling you and get it fixed to get rid of that warning message. 您可以尝试找出问题所在,并加以解决,以消除该警告消息。 If they are passing you a cookie, they probably want you to be able to receive it properly and use it. 如果他们向您传递了cookie,则可能希望您能够正确接收它并使用它。 If that's not an option, you can add the following config setting to your actor system: 如果这不是一个选项,则可以将以下配置设置添加到actor系统:

akka.http.server.parsing.illegal-header-warnings = on

That will quiet that warning for you if you can't get the underlying issue fixed. 如果您无法解决根本问题,那将为您消除该警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM