diff --git a/akka-http-tests/src/test/scala/akka/http/server/directives/BasicDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/server/directives/BasicDirectivesSpec.scala index 18a0fc37e5..61a192ad72 100644 --- a/akka-http-tests/src/test/scala/akka/http/server/directives/BasicDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/server/directives/BasicDirectivesSpec.scala @@ -7,10 +7,10 @@ package directives class BasicDirectivesSpec extends RoutingSpec { - "The `rewriteUnmatchedPath` directive" should { - "rewrite the unmatched path" in { + "The `mapUnmatchedPath` directive" should { + "map the unmatched path" in { Get("/abc") ~> { - rewriteUnmatchedPath(_ / "def") { + mapUnmatchedPath(_ / "def") { path("abc" / "def") { completeOk } } } ~> check { response shouldEqual Ok } diff --git a/akka-http-tests/src/test/scala/akka/http/server/directives/MiscDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/server/directives/MiscDirectivesSpec.scala index 41bfea88dd..fd182d35c8 100644 --- a/akka-http-tests/src/test/scala/akka/http/server/directives/MiscDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/server/directives/MiscDirectivesSpec.scala @@ -13,20 +13,20 @@ import Uri._ class MiscDirectivesSpec extends RoutingSpec { - "the clientIP directive" should { + "the extractClientIP directive" should { "extract from a X-Forwarded-For header" in { Get() ~> addHeaders(`X-Forwarded-For`("2.3.4.5"), RawHeader("x-real-ip", "1.2.3.4")) ~> { - clientIP { echoComplete } + extractClientIP { echoComplete } } ~> check { responseAs[String] shouldEqual "2.3.4.5" } } "extract from a Remote-Address header" in { Get() ~> addHeaders(RawHeader("x-real-ip", "1.2.3.4"), `Remote-Address`(RemoteAddress("5.6.7.8"))) ~> { - clientIP { echoComplete } + extractClientIP { echoComplete } } ~> check { responseAs[String] shouldEqual "5.6.7.8" } } "extract from a X-Real-IP header" in { Get() ~> addHeader(RawHeader("x-real-ip", "1.2.3.4")) ~> { - clientIP { echoComplete } + extractClientIP { echoComplete } } ~> check { responseAs[String] shouldEqual "1.2.3.4" } } } diff --git a/akka-http-tests/src/test/scala/akka/http/server/directives/PathDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/server/directives/PathDirectivesSpec.scala index 97d2f1ab24..c532717a11 100644 --- a/akka-http-tests/src/test/scala/akka/http/server/directives/PathDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/server/directives/PathDirectivesSpec.scala @@ -7,7 +7,7 @@ package akka.http.server.directives import akka.http.server._ class PathDirectivesSpec extends RoutingSpec { - val echoUnmatchedPath = unmatchedPath { echoComplete } + val echoUnmatchedPath = extractUnmatchedPath { echoComplete } def echoCaptureAndUnmatchedPath[T]: T ⇒ Route = capture ⇒ ctx ⇒ ctx.complete(capture.toString + ":" + ctx.unmatchedPath) diff --git a/akka-http-tests/src/test/scala/akka/http/server/directives/SchemeDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/server/directives/SchemeDirectivesSpec.scala index 30aa251c3f..cce87b45d0 100644 --- a/akka-http-tests/src/test/scala/akka/http/server/directives/SchemeDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/server/directives/SchemeDirectivesSpec.scala @@ -8,9 +8,9 @@ package directives import akka.http.model.StatusCodes._ class SchemeDirectivesSpec extends RoutingSpec { - "the schemeName directive" should { + "the extractScheme directive" should { "extract the Uri scheme" in { - Put("http://localhost/", "Hello") ~> schemeName { echoComplete } ~> check { responseAs[String] shouldEqual "http" } + Put("http://localhost/", "Hello") ~> extractScheme { echoComplete } ~> check { responseAs[String] shouldEqual "http" } } } diff --git a/akka-http/src/main/scala/akka/http/server/RequestContext.scala b/akka-http/src/main/scala/akka/http/server/RequestContext.scala index 3019ca4552..e650e77ab8 100644 --- a/akka-http/src/main/scala/akka/http/server/RequestContext.scala +++ b/akka-http/src/main/scala/akka/http/server/RequestContext.scala @@ -84,7 +84,7 @@ trait RequestContext { /** * Returns a copy of this context with the HttpRequest transformed by the given function. */ - def withRequestMapped(f: HttpRequest ⇒ HttpRequest): RequestContext + def mapRequest(f: HttpRequest ⇒ HttpRequest): RequestContext /** * Returns a copy of this context with the unmatched path updated to the given one. @@ -94,7 +94,7 @@ trait RequestContext { /** * Returns a copy of this context with the unmatchedPath transformed by the given function. */ - def withUnmatchedPathMapped(f: Uri.Path ⇒ Uri.Path): RequestContext + def mapUnmatchedPath(f: Uri.Path ⇒ Uri.Path): RequestContext /** * Removes a potentially existing Accept header from the request headers. diff --git a/akka-http/src/main/scala/akka/http/server/RequestContextImpl.scala b/akka-http/src/main/scala/akka/http/server/RequestContextImpl.scala index 6a5295e418..ba4660dcc3 100644 --- a/akka-http/src/main/scala/akka/http/server/RequestContextImpl.scala +++ b/akka-http/src/main/scala/akka/http/server/RequestContextImpl.scala @@ -50,13 +50,13 @@ private[http] class RequestContextImpl( override def withSettings(settings: RoutingSettings): RequestContext = copy(settings = settings) - override def withRequestMapped(f: HttpRequest ⇒ HttpRequest): RequestContext = + override def mapRequest(f: HttpRequest ⇒ HttpRequest): RequestContext = copy(request = f(request)) override def withUnmatchedPath(path: Uri.Path): RequestContext = copy(unmatchedPath = path) - override def withUnmatchedPathMapped(f: Uri.Path ⇒ Uri.Path): RequestContext = + override def mapUnmatchedPath(f: Uri.Path ⇒ Uri.Path): RequestContext = copy(unmatchedPath = f(unmatchedPath)) override def withContentNegotiationDisabled: RequestContext = diff --git a/akka-http/src/main/scala/akka/http/server/directives/BasicDirectives.scala b/akka-http/src/main/scala/akka/http/server/directives/BasicDirectives.scala index ba4b659b36..384d04ae74 100644 --- a/akka-http/src/main/scala/akka/http/server/directives/BasicDirectives.scala +++ b/akka-http/src/main/scala/akka/http/server/directives/BasicDirectives.scala @@ -23,7 +23,7 @@ trait BasicDirectives { mapInnerRoute { inner ⇒ ctx ⇒ inner(f(ctx)) } def mapRequest(f: HttpRequest ⇒ HttpRequest): Directive0 = - mapRequestContext(_ withRequestMapped f) + mapRequestContext(_ mapRequest f) def mapRouteResultFuture(f: Future[RouteResult] ⇒ Future[RouteResult]): Directive0 = Directive { inner ⇒ ctx ⇒ f(inner(())(ctx)) } @@ -111,23 +111,23 @@ trait BasicDirectives { /** * Transforms the unmatchedPath of the RequestContext using the given function. */ - def rewriteUnmatchedPath(f: Uri.Path ⇒ Uri.Path): Directive0 = - mapRequestContext(_ withUnmatchedPathMapped f) + def mapUnmatchedPath(f: Uri.Path ⇒ Uri.Path): Directive0 = + mapRequestContext(_ mapUnmatchedPath f) /** * Extracts the unmatched path from the RequestContext. */ - def unmatchedPath: Directive1[Uri.Path] = BasicDirectives._unmatchedPath + def extractUnmatchedPath: Directive1[Uri.Path] = BasicDirectives._extractUnmatchedPath /** * Extracts the complete request. */ - def requestInstance: Directive1[HttpRequest] = BasicDirectives._requestInstance + def extractRequest: Directive1[HttpRequest] = BasicDirectives._extractRequest /** * Extracts the complete request URI. */ - def requestUri: Directive1[Uri] = BasicDirectives._requestUri + def extractUri: Directive1[Uri] = BasicDirectives._extractUri /** * Runs its inner route with the given alternative [[ExecutionContext]]. @@ -177,9 +177,9 @@ trait BasicDirectives { } object BasicDirectives extends BasicDirectives { - private val _unmatchedPath: Directive1[Uri.Path] = extract(_.unmatchedPath) - private val _requestInstance: Directive1[HttpRequest] = extract(_.request) - private val _requestUri: Directive1[Uri] = extract(_.request.uri) + private val _extractUnmatchedPath: Directive1[Uri.Path] = extract(_.unmatchedPath) + private val _extractRequest: Directive1[HttpRequest] = extract(_.request) + private val _extractUri: Directive1[Uri] = extract(_.request.uri) private val _extractExecutionContext: Directive1[ExecutionContext] = extract(_.executionContext) private val _extractLog: Directive1[LoggingAdapter] = extract(_.log) private val _extractSettings: Directive1[RoutingSettings] = extract(_.settings) diff --git a/akka-http/src/main/scala/akka/http/server/directives/CacheConditionDirectives.scala b/akka-http/src/main/scala/akka/http/server/directives/CacheConditionDirectives.scala index 2f48420b42..daeb506ed1 100644 --- a/akka-http/src/main/scala/akka/http/server/directives/CacheConditionDirectives.scala +++ b/akka-http/src/main/scala/akka/http/server/directives/CacheConditionDirectives.scala @@ -35,7 +35,7 @@ trait CacheConditionDirectives { def complete304(): Route = addResponseHeaders(complete(HttpResponse(NotModified))) def complete412(): Route = _.complete(PreconditionFailed) - requestInstance.flatMap { request ⇒ + extractRequest.flatMap { request ⇒ import request._ mapInnerRoute { route ⇒ def innerRouteWithRangeHeaderFilteredOut: Route = diff --git a/akka-http/src/main/scala/akka/http/server/directives/HostDirectives.scala b/akka-http/src/main/scala/akka/http/server/directives/HostDirectives.scala index 26c274a7e6..fdf05ea277 100644 --- a/akka-http/src/main/scala/akka/http/server/directives/HostDirectives.scala +++ b/akka-http/src/main/scala/akka/http/server/directives/HostDirectives.scala @@ -15,7 +15,7 @@ trait HostDirectives { /** * Extracts the hostname part of the Host header value in the request. */ - def hostName: Directive1[String] = HostDirectives._hostName + def extractHost: Directive1[String] = HostDirectives._extractHost /** * Rejects all requests with a host name different from the given ones. @@ -25,7 +25,7 @@ trait HostDirectives { /** * Rejects all requests for whose host name the given predicate function returns false. */ - def host(predicate: String ⇒ Boolean): Directive0 = hostName.require(predicate) + def host(predicate: String ⇒ Boolean): Directive0 = extractHost.require(predicate) /** * Rejects all requests with a host name that doesn't have a prefix matching the given regular expression. @@ -35,7 +35,7 @@ trait HostDirectives { */ def host(regex: Regex): Directive1[String] = { def forFunc(regexMatch: String ⇒ Option[String]): Directive1[String] = { - hostName.flatMap { name ⇒ + extractHost.flatMap { name ⇒ regexMatch(name) match { case Some(matched) ⇒ provide(matched) case None ⇒ reject @@ -56,6 +56,6 @@ trait HostDirectives { object HostDirectives extends HostDirectives { import BasicDirectives._ - private val _hostName: Directive1[String] = + private val _extractHost: Directive1[String] = extract(_.request.uri.authority.host.address) } diff --git a/akka-http/src/main/scala/akka/http/server/directives/MiscDirectives.scala b/akka-http/src/main/scala/akka/http/server/directives/MiscDirectives.scala index 9eef1fa050..e0d0cd28d3 100644 --- a/akka-http/src/main/scala/akka/http/server/directives/MiscDirectives.scala +++ b/akka-http/src/main/scala/akka/http/server/directives/MiscDirectives.scala @@ -22,7 +22,7 @@ trait MiscDirectives { * Directive extracting the IP of the client from either the X-Forwarded-For, Remote-Address or X-Real-IP header * (in that order of priority). */ - def clientIP: Directive1[RemoteAddress] = MiscDirectives._clientIP + def extractClientIP: Directive1[RemoteAddress] = MiscDirectives._extractClientIP /** * Rejects the request if its entity is not empty. @@ -49,7 +49,7 @@ object MiscDirectives extends MiscDirectives { import RouteDirectives._ import RouteResult._ - private val _clientIP: Directive1[RemoteAddress] = + private val _extractClientIP: Directive1[RemoteAddress] = headerValuePF { case `X-Forwarded-For`(Seq(address, _*)) ⇒ address } | headerValuePF { case `Remote-Address`(address) ⇒ address } | headerValuePF { case h if h.is("x-real-ip") ⇒ RemoteAddress(h.value) } diff --git a/akka-http/src/main/scala/akka/http/server/directives/SchemeDirectives.scala b/akka-http/src/main/scala/akka/http/server/directives/SchemeDirectives.scala index 2616fb137f..6e7815f68a 100644 --- a/akka-http/src/main/scala/akka/http/server/directives/SchemeDirectives.scala +++ b/akka-http/src/main/scala/akka/http/server/directives/SchemeDirectives.scala @@ -11,17 +11,17 @@ trait SchemeDirectives { /** * Extracts the Uri scheme from the request. */ - def schemeName: Directive1[String] = SchemeDirectives._schemeName + def extractScheme: Directive1[String] = SchemeDirectives._extractScheme /** * Rejects all requests whose Uri scheme does not match the given one. */ def scheme(name: String): Directive0 = - schemeName.require(_ == name, SchemeRejection(name)) & cancelRejections(classOf[SchemeRejection]) + extractScheme.require(_ == name, SchemeRejection(name)) & cancelRejections(classOf[SchemeRejection]) } object SchemeDirectives extends SchemeDirectives { import BasicDirectives._ - private val _schemeName: Directive1[String] = extract(_.request.uri.scheme) + private val _extractScheme: Directive1[String] = extract(_.request.uri.scheme) }