在我的 akka-http 应用程序中,我从另一个安全服务返回了一个响应,该响应带有一个WWW-Authenticate
标头:当 akka-http 解析此标头,然后将WWW-Authenticate
值呈现为一个字符串时,其中一个参数上的引号丢失了。我是否在渲染中遗漏了某些内容,或者这可能是 akka-http 错误?
这是一个测试用例:
import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.model.HttpHeader.ParsingResult
import akka.http.scaladsl.model.headers.{`WWW-Authenticate`, HttpChallenge}
import org.scalatest.{Matchers, WordSpec}
class wwwAuthenticateParserTest extends WordSpec with Matchers {
"WWW-Authenticate header" should {
"have correctly-quoted strings" in {
val rawHeader = HttpHeader.parse("WWW-Authenticate",
"Bearer error=\"invalid_request\", error_description=\"Access token is not found\"")
val expectedHeader = `WWW-Authenticate`(HttpChallenge("Bearer",
"",
Map("error" -> "invalid_request", "error_description" -> "Access token is not found")))
rawHeader match {
case ParsingResult.Ok(`WWW-Authenticate`(challenges), _) =>
challenges.head should be(expectedHeader.challenges.head)
challenges.head.params("error") should be("invalid_request")
challenges.head.toString should be("Bearer realm=\"\",error=\"invalid_request\",error_description=\"Access token is not found\"")
case _ => ???
}
}
invalid_request
第三个断言失败,缺少引号。akka-http 应用程序发送的响应的标头中也缺少引号。