From 0925a23be5ec0ed82158e562ea3fba615335ee0e Mon Sep 17 00:00:00 2001 From: Mathias Date: Mon, 30 Mar 2015 10:55:41 +0200 Subject: [PATCH] =htp #17082 fix response message generated for `MethodRejection` --- .../src/test/scala/akka/http/server/BasicRouteSpecs.scala | 5 ++++- .../src/main/scala/akka/http/server/RejectionHandler.scala | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/akka-http-tests/src/test/scala/akka/http/server/BasicRouteSpecs.scala b/akka-http-tests/src/test/scala/akka/http/server/BasicRouteSpecs.scala index 1ef6c0ada8..4c18c042e9 100644 --- a/akka-http-tests/src/test/scala/akka/http/server/BasicRouteSpecs.scala +++ b/akka-http-tests/src/test/scala/akka/http/server/BasicRouteSpecs.scala @@ -167,7 +167,10 @@ class BasicRouteSpecs extends RoutingSpec { Get("/abc") ~> Route.seal { post { completeOk } ~ authorize(false) { completeOk } - } ~> check { status shouldEqual StatusCodes.MethodNotAllowed } + } ~> check { + status shouldEqual StatusCodes.MethodNotAllowed + responseAs[String] shouldEqual "HTTP method not allowed, supported methods: POST" + } Get("/abc") ~> Route.seal { authorize(false) { completeOk } ~ diff --git a/akka-http/src/main/scala/akka/http/server/RejectionHandler.scala b/akka-http/src/main/scala/akka/http/server/RejectionHandler.scala index c7f74f3849..828df9b73e 100644 --- a/akka-http/src/main/scala/akka/http/server/RejectionHandler.scala +++ b/akka-http/src/main/scala/akka/http/server/RejectionHandler.scala @@ -122,8 +122,8 @@ object RejectionHandler { complete(BadRequest, "Uri scheme not allowed, supported schemes: " + schemes) } .handleAll[MethodRejection] { rejections ⇒ - val methods = rejections.map(_.supported) - complete(MethodNotAllowed, List(Allow(methods)), "HTTP method not allowed, supported methods: " + methods.mkString(", ")) + val (methods, names) = rejections.map(r ⇒ r.supported -> r.supported.name).unzip + complete(MethodNotAllowed, List(Allow(methods)), "HTTP method not allowed, supported methods: " + names.mkString(", ")) } .handle { case AuthorizationFailedRejection ⇒