Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 665
zaxme Avatar asked Sep 07 '25 10:09

zaxme


1 Answers

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. 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. If that's not an option, you can add the following config setting to your actor system:

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

That will quiet that warning for you if you can't get the underlying issue fixed.

like image 185
cmbaxter Avatar answered Sep 10 '25 06:09

cmbaxter