basho/webmachine — pull request #180 by seth (2013-12-06 21:18:48+00:00)
Title: Support IPv6 address literals when parsing Host header

IPv6 address literals are enclosed in square brackets when used in a
URL [1]. This patch allows the host/port parsing in dispatch/4 to
handle such values.

The adjusted parsing implementation attempts to normalize ipv6
literals and adds brackets if they are missing. Some clients (including
ibrowse 4.0.1) send a Host header with a non-bracketed address. With
the normalization, the value returned by wrq:host_tokens/1 will have
brackets if it is an ipv6 literal.

When a non-bracketed Host header containing an ipv6 address literal is
encountered, the right thing will happen if an explicit port is given
in the header value. Otherwise, the last section of the ipv6 address
will be parsed as the port. Since the client is sending an incorrect,
it seemed not worth adding additional workarounds for this case.

Finally, this patch introduces test/wm_integration_test and a minimal
resource module to verify the Host header and host tokens
behavior. ibrowse and curl are used to make HTTP requests for
testing. In R15, httpc is unable to make ipv6 requests. Curl used as
it gives the correct behavior -- the test is guarded and will be
skipped without failure if no curl executable is found on PATH.

[1]: http://www.ietf.org/rfc/rfc2732.txt