rest-client/rest-client — pull request #333 by jrafanie (2014-11-24 17:38:53+00:00)
Title: ruby 2+: delegate IPv6 [] wrapping to net/http by passing a URI object.

Note: this is similar but different than #332. Both issues are required to fix using IPv6 addresses with rest-client on ruby 2.0+.

net/http with Ruby 2+ will handle setting the Host header in the request correctly when you pass a URI object.

See: https://github.com/ruby/ruby/blob/8eb0c810b228df1f8352c005a7ae882ad4179b4b/lib/net/http/generic_request.rb#L17

Fixes 400/bad request error with IPv6 addresses.

For example, a good request with an ipv4 address, such as: 127.0.0.1:

```
starting SSL for 127.0.0.1:443...
SSL established
<- "GET /api HTTP/1.1\r\nAccept: */*; q=0.5, application/xml\r\nAccept-Encoding: gzip, deflate\r\nPrefer: persistent-auth\r\nUser-Agent: Ruby\r\nAuthorization: Basic ...\r\nHost: 127.0.0.1\r\n\r\n"
-> "HTTP/1.1 200 OK\r\n"
```

Now, a BAD request with the existing code and an ipv6 address, such as ::1:

```
starting SSL for ::1:443...
SSL established
<- "GET /api HTTP/1.1\r\nAccept: */*; q=0.5, application/xml\r\nAccept-Encoding: gzip, deflate\r\nPrefer: persistent-auth\r\nUser-Agent: Ruby\r\nAuthorization: Basic ...\r\nHost: ::1\r\n\r\n"
-> "HTTP/1.1 400 Bad Request\r\n"
```

Now, the same request with the changed code:

```
starting SSL for ::1:443...
SSL established
<- "GET /api HTTP/1.1\r\nAccept: */*; q=0.5, application/xml\r\nAccept-Encoding: gzip, deflate\r\nPrefer: persistent-auth\r\nUser-Agent: Ruby\r\nAuthorization: Basic ...\r\nHost: [::1]\r\n\r\n"
-> "HTTP/1.1 200 OK\r\n"
```

Note: the Host request header is properly wrapped in [].