{"action":"created","issue":{"url":"https://api.github.com/repos/excon/excon/issues/449","labels_url":"https://api.github.com/repos/excon/excon/issues/449/labels{/name}","comments_url":"https://api.github.com/repos/excon/excon/issues/449/comments","events_url":"https://api.github.com/repos/excon/excon/issues/449/events","html_url":"https://github.com/excon/excon/pull/449","id":51154406,"number":449,"title":"Unwrap ipv6 addresses for use with sockets","user":{"login":"jrafanie","id":19339,"avatar_url":"https://avatars.githubusercontent.com/u/19339?v=3","gravatar_id":"","url":"https://api.github.com/users/jrafanie","html_url":"https://github.com/jrafanie","followers_url":"https://api.github.com/users/jrafanie/followers","following_url":"https://api.github.com/users/jrafanie/following{/other_user}","gists_url":"https://api.github.com/users/jrafanie/gists{/gist_id}","starred_url":"https://api.github.com/users/jrafanie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrafanie/subscriptions","organizations_url":"https://api.github.com/users/jrafanie/orgs","repos_url":"https://api.github.com/users/jrafanie/repos","events_url":"https://api.github.com/users/jrafanie/events{/privacy}","received_events_url":"https://api.github.com/users/jrafanie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2014-12-05T22:36:44Z","updated_at":"2015-01-02T18:15:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/excon/excon/pulls/449","html_url":"https://github.com/excon/excon/pull/449","diff_url":"https://github.com/excon/excon/pull/449.diff","patch_url":"https://github.com/excon/excon/pull/449.patch"},"body":"Literal IPv6 addresses, such as ::1, have a few rules in regards to their use:\r\n* They must be wrapped in [], such as [::1] when used in URL/URIs and in the Host Request header field.\r\nSee: https://bugzilla.mozilla.org/show_bug.cgi?id=45891\r\nTL;DR: \r\nRFC 2617 says Host = host : port\r\nRFC 2732 says, host must be wrapped in [], so, we need **Host = [::1]:9292**\r\n\r\n* They must be unwrapped, \"::1\", when passed to sockets.\r\nSee: https://github.com/ruby/ruby/blob/e70210cad637c5be31709f65c0eb9603f8ec18a1/lib/uri/generic.rb#L234\r\n\r\n#### To illustrate the problem that this pull request fixes:\r\n```ruby\r\nirb(main):001:0> require 'excon'\r\n=> true\r\nirb(main):002:0> Excon.new(\"http://[::1]:9292\").request\r\nExcon::Errors::SocketError: getaddrinfo: nodename nor servname provided, or not known (SocketError)\r\n...\r\n```\r\n\r\nI get a getaddrinfo error **because Excon is sending [::1]** directly to the socket layer.\r\n\r\n#### Using this PR's fixed excon:\r\n\r\n```ruby\r\n$ bundle console\r\nResolving dependencies...\r\nirb(main):001:0> require 'excon'\r\n=> false\r\n\r\nirb(main):002:0> Excon.new(\"http://[::1]:9292\").request\r\nExcon::Errors::SocketError: Connection refused - connect(2) (Errno::ECONNREFUSED)\r\n...\r\n```\r\n**Note 1**: Instead of getaddrinfo error, I get connection refused because I have nothing listening.\r\n\r\n**Note 2**: I don't like borrowing from ruby's URI class, I'd rather let URI handle this...\r\n\r\n**Note 3**: It's unfortunate I have to unwrap each time we pass to the socket but I couldn't find an easy way to handle the request host header separately from the socket host value.  The same data/datum is used for both.  In other libraries, you can keep things as URI objects and call hostname for unwrapped (`::1`) and host for wrapped (`[::1]`).  As mentioned above in note 2, this is desirable but unfortunately, excon would have to change in many places to keep the host/port/scheme/path, etc. in URI format and extract out the parts you need when needed.  If we did do this though, we could then call URI#hostname where I'm currently unwrapping the [] for use in the socket code.\r\n\r\nSee also:\r\nhttps://github.com/nahi/httpclient/pull/176\r\nhttps://github.com/rest-client/rest-client/pull/332\r\nhttps://github.com/rest-client/rest-client/pull/333"},"comment":{"url":"https://api.github.com/repos/excon/excon/issues/comments/68548149","html_url":"https://github.com/excon/excon/pull/449#issuecomment-68548149","issue_url":"https://api.github.com/repos/excon/excon/issues/449","id":68548149,"user":{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},"created_at":"2015-01-02T18:15:34Z","updated_at":"2015-01-02T18:15:34Z","body":"@jrafanie Would it make sense to change to the code to allow either a String *or* a URI, and warn a deprecation if the String comes in?  That way, you can let the tests/testing tell you where any additional fixes are needed, and if anything is missed it at least won't break."}}