{"action":"created","issue":{"url":"https://api.github.com/repos/akka/akka/issues/20203","repository_url":"https://api.github.com/repos/akka/akka","labels_url":"https://api.github.com/repos/akka/akka/issues/20203/labels{/name}","comments_url":"https://api.github.com/repos/akka/akka/issues/20203/comments","events_url":"https://api.github.com/repos/akka/akka/issues/20203/events","html_url":"https://github.com/akka/akka/issues/20203","id":145295704,"number":20203,"title":"I think that headerValueByType does not work always with custom headers","user":{"login":"xelax","id":438260,"avatar_url":"https://avatars.githubusercontent.com/u/438260?v=3","gravatar_id":"","url":"https://api.github.com/users/xelax","html_url":"https://github.com/xelax","followers_url":"https://api.github.com/users/xelax/followers","following_url":"https://api.github.com/users/xelax/following{/other_user}","gists_url":"https://api.github.com/users/xelax/gists{/gist_id}","starred_url":"https://api.github.com/users/xelax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xelax/subscriptions","organizations_url":"https://api.github.com/users/xelax/orgs","repos_url":"https://api.github.com/users/xelax/repos","events_url":"https://api.github.com/users/xelax/events{/privacy}","received_events_url":"https://api.github.com/users/xelax/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-01T22:00:16Z","updated_at":"2016-04-02T06:02:04Z","closed_at":null,"body":"I tried headerValueByType with my own custom header but it does not seem to work. I put your own test in my own project and in that context it fails as well. Here is my test case, which fails with:\r\n\r\nRun starting. Expected test count is: 1\r\nApiSpecs:\r\nApiSpecs\r\n- should be able to extract in routing DSL via headerValueByType *** FAILED ***\r\n  Request was rejected with rejection MissingHeaderRejection(ApiTokenHeader) (DynamicVariable.scala:58)\r\nRun completed in 697 milliseconds.\r\nTotal number of tests run: 1\r\nSuites: completed 1, aborted 0\r\nTests: succeeded 0, failed 1, canceled 0, ignored 0, pending 0\r\n*** 1 TEST FAILED ***\r\n\r\n\r\n\r\n```\r\nimport org.scalatest._\r\nimport akka.http.scaladsl.testkit.ScalatestRouteTest\r\n\r\nimport akka.http.scaladsl.model.headers.RawHeader\r\nimport akka.http.scaladsl.model.headers._\r\nimport akka.http.scaladsl.model._\r\nimport akka.http.scaladsl.server.MissingHeaderRejection\r\nimport scala.util.Try\r\nimport akka.http.scaladsl.server.Directives\r\n\r\nobject ApiToken {\r\n  final class ApiTokenHeader(token: String) extends ModeledCustomHeader[ApiTokenHeader] {\r\n    def renderInRequests = false\r\n    def renderInResponses = false\r\n    override val companion = ApiTokenHeader\r\n    override def value: String = token\r\n  }\r\n  object ApiTokenHeader extends ModeledCustomHeaderCompanion[ApiTokenHeader] {\r\n    def renderInRequests = false\r\n    def renderInResponses = false\r\n    override val name = \"apiKey\"\r\n    override def parse(value: String) = Try(new ApiTokenHeader(value))\r\n  }\r\n}\r\n\r\nclass ApiSpecs extends FlatSpec with Matchers with Directives with ScalatestRouteTest {\r\n  import ApiToken._\r\n\r\n  \"ApiSpecs\" should \"be able to extract in routing DSL via headerValueByType\" in {\r\n    val routes = headerValueByType[ApiTokenHeader]() { token ⇒\r\n      val ApiTokenHeader(t) = token\r\n      complete(s\"extracted> $t\")\r\n    }\r\n\r\n    Get().withHeaders(RawHeader(\"apiKey\", \"TheKey\")) ~> routes ~> check {\r\n      status should ===(StatusCodes.OK)\r\n      responseAs[String] should ===(\"extracted> apiKey: TheKey\")\r\n    }\r\n\r\n    Get().withHeaders(RawHeader(\"somethingElse\", \"TheKey\")) ~> routes ~> check {\r\n      rejection should ===(MissingHeaderRejection(\"ApiTokenHeader\"))\r\n    }\r\n\r\n    Get().withHeaders(ApiTokenHeader(\"TheKey\")) ~> routes ~> check {\r\n      status should ===(StatusCodes.OK)\r\n      responseAs[String] should ===(\"extracted> apiKey: TheKey\")\r\n    }\r\n  }\r\n}\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/akka/akka/issues/comments/204653972","html_url":"https://github.com/akka/akka/issues/20203#issuecomment-204653972","issue_url":"https://api.github.com/repos/akka/akka/issues/20203","id":204653972,"user":{"login":"xelax","id":438260,"avatar_url":"https://avatars.githubusercontent.com/u/438260?v=3","gravatar_id":"","url":"https://api.github.com/users/xelax","html_url":"https://github.com/xelax","followers_url":"https://api.github.com/users/xelax/followers","following_url":"https://api.github.com/users/xelax/following{/other_user}","gists_url":"https://api.github.com/users/xelax/gists{/gist_id}","starred_url":"https://api.github.com/users/xelax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xelax/subscriptions","organizations_url":"https://api.github.com/users/xelax/orgs","repos_url":"https://api.github.com/users/xelax/repos","events_url":"https://api.github.com/users/xelax/events{/privacy}","received_events_url":"https://api.github.com/users/xelax/received_events","type":"User","site_admin":false},"created_at":"2016-04-02T06:02:04Z","updated_at":"2016-04-02T06:02:04Z","body":"tested with akka 2.3.15 and akka http stream 2.0.4"}}