Skip to content

Commit

Permalink
Removing logging & unrequired header removal.
Browse files Browse the repository at this point in the history
We now have a working router.
  • Loading branch information
Matthew Wall committed Dec 2, 2011
1 parent 8a64344 commit 730a7a5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
15 changes: 2 additions & 13 deletions router/src/main/scala/uk/gov/gds/router/util/HttpProxy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ object HttpProxy extends Logging {
private val httpClient = configureHttpClient

private val requestHeadersToFilter = List(
"X-Forwarded-For",
"X-Forwarded-Port",
HTTP.TRANSFER_ENCODING,
HTTP.CONTENT_LEN,
HTTP.TARGET_HOST)
Expand All @@ -47,24 +45,15 @@ object HttpProxy extends Logging {

requestInfo.headers.filter(h => !requestHeadersToFilter.contains(h._1)).foreach {
case (name, value) => {
logger.info("Request header " + name + " " + value)
message.addHeader(name, value)
}
}

requestInfo.headers.filter(h => h._1 == HTTP.TARGET_HOST).foreach(h => {
logger.info("*Request header X-Forwarded-Host " + h._2)
message.addHeader("X-Forwarded-Host", h._2)
}
)
requestInfo.headers.filter(h => h._1 == HTTP.TARGET_HOST).foreach(h => message.addHeader("X-Forwarded-Host", h._2))

val targetResponse = httpClient.execute(message)
clientResponse.setStatus(targetResponse.getStatusLine.getStatusCode)
targetResponse.getAllHeaders.foreach(h => {
logger.info("Response header " + h.getName + " " + h.getValue)
clientResponse.setHeader(h.getName, h.getValue)
}
)
targetResponse.getAllHeaders.foreach(h => clientResponse.setHeader(h.getName, h.getValue))

Option(targetResponse.getEntity) match {
case Some(entity) => entity.writeTo(clientResponse.getOutputStream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,6 @@ class RouterIntegrationTest extends MongoDatabaseBackedTest with ShouldMatchers
responseWithCookiesFromServer.body.contains("test-cookie=this is a cookie") should be(true)
}

test("Does not pass through X-Forwarded-For or X-Forwarded-Port") {
val httpGet = new HttpGet(buildUrl("/route/test/incoming-headers"))
httpGet.addHeader("X-Forwarded-For", "127.0.0.1")
httpGet.addHeader("X-Forwarded-Port", "80")
val response = Response(httpGet)
response.body.contains("X-Forwarded-For") should not be(true)
response.body.contains("X-Forwarded-Port") should not be(true)
}

test("Original host sent to backend as X_FORWARDED_HOST") {
val httpGet = new HttpGet(buildUrl("/route/test/incoming-headers"))
httpGet.addHeader("Host", "original.example.com:3100")
Expand Down

0 comments on commit 730a7a5

Please sign in to comment.