Skip to content

Commit

Permalink
Lowercase Host header value in HTTP identifier
Browse files Browse the repository at this point in the history
In accordance to RFC 2616. Handles linkerd#106
  • Loading branch information
ashald committed Sep 13, 2016
1 parent 30429c0 commit ef26187
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion linkerd/docs/protocol-http.md
Expand Up @@ -81,7 +81,8 @@ kind | _required_ | Either [`io.l5d.methodAndHost`](#method-and-host-identifier)
kind: `io.l5d.methodAndHost`.

With this identifier, HTTP requests are turned into logical names using a
combination of Host header, method, and (optionally) URI.
combination of `Host` header, method, and (optionally) URI. `Host`
header value is lower-cased as per `RFC 2616`.

#### Namer Configuration:

Expand Down
Expand Up @@ -34,7 +34,7 @@ case class MethodAndHostIdentifier(
case Version.Http11 =>
req.host match {
case Some(host) if host.nonEmpty =>
val dst = mkPath(Path.Utf8("1.1", req.method.toString, host) ++ suffix(req))
val dst = mkPath(Path.Utf8("1.1", req.method.toString, host.toLowerCase) ++ suffix(req))
Future.value(new IdentifiedRequest(dst, req))
case _ =>
Future.value(
Expand Down
Expand Up @@ -3,10 +3,8 @@ package io.buoyant.router.http
import com.twitter.finagle.Path
import com.twitter.finagle.buoyant.Dst
import com.twitter.finagle.http.{Method, Request, Version}
import com.twitter.util._
import io.buoyant.router.RoutingFactory.{IdentifiedRequest, UnidentifiedRequest}
import io.buoyant.test.{Exceptions, Awaits}
import java.net.SocketAddress
import io.buoyant.test.{Awaits, Exceptions}
import org.scalatest.FunSuite

class MethodAndHostIdentifierTest extends FunSuite with Awaits with Exceptions {
Expand All @@ -22,7 +20,7 @@ class MethodAndHostIdentifierTest extends FunSuite with Awaits with Exceptions {
val identifier = MethodAndHostIdentifier(Path.Utf8("https"), false)
val req = Request()
req.uri = "/some/path?other=stuff"
req.host = "domain"
req.host = "DoMaiN" // should be lowercased as per RFC 2616
assert(
await(identifier(req)).asInstanceOf[IdentifiedRequest[Request]].dst ==
Dst.Path(Path.read("/https/1.1/GET/domain"))
Expand Down

0 comments on commit ef26187

Please sign in to comment.