Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package directives
import spray.can.Http
import akka.io.IO
import akka.actor.ActorSystem
import spray.http.{ HttpRequest, Uri }
import spray.http.{ HttpHeader, HttpRequest, Uri }

trait ProxyDirectives {

Expand All @@ -29,20 +29,28 @@ trait ProxyDirectives {
ctx ⇒ transport.tell(f(ctx), ctx.responder)
}

private def stripHost(headers: List[HttpHeader] = Nil) = {
headers.filterNot(header => header.is("host"))
}

/**
* proxy the request to the specified uri
*
*/
def proxyTo(uri: Uri)(implicit system: ActorSystem): Route = {
sending(_.request.copy(uri = uri))
sending(ctx => ctx.request.copy(
uri = uri,
headers = stripHost(ctx.request.headers)))
}

/**
* proxy the request to the specified uri with the unmatched path
*
*/
def proxyToUnmatchedPath(uri: Uri)(implicit system: ActorSystem): Route = {
sending(ctx ⇒ ctx.request.copy(uri = uri.withPath(uri.path.++(ctx.unmatchedPath))))
sending(ctx ⇒ ctx.request.copy(
uri = uri.withPath(uri.path.++(ctx.unmatchedPath)),
headers = stripHost(ctx.request.headers)))
}
}

Expand Down