Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Use URI to build URIs and hostname= to wrap ipv6 addresses in brackets. #16

Merged

Conversation

jrafanie
Copy link
Member

@jrafanie
Copy link
Member Author

@Fryguy @brandondunne Please review.

Related: rest-client/rest-client#332

@Fryguy
Copy link
Member

Fryguy commented Nov 19, 2014

Looks good, will merge when green.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.62%) when pulling 75211f6 on jrafanie:use_uri_and_uri_hostname_equals_to_build_uris into 475a6ec on ManageIQ:master.

end
require 'uri'
uri = URI::Generic.build(:scheme => scheme.to_s, :port => port)
uri.hostname = server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrafanie Any reason not to add :host to the line above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we could avoid the variable assignment and just do:

def base_uri
  require 'uri'
  URI::Generic.build(:scheme => scheme.to_s, :host => server, :port => port).to_s
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind... Now I see that #hostname= handles IPv6

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandondunne good call, I'm actually going to open a PR on ruby to fix build so I can pass :host => "::1" and have it run hostname= under the covers so it handles "bare" ipv6 addresses. Once that is fixed in upstream, this code can be simplified as you suggest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrafanie Is there any disadvantage to that? I guess worst case, it could be opened as allowing a :hostname key so that they match the attribute methods, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no disadvantage. Clients shouldn't need to know that ::1 needs to become http://[::1] in URIs. We'll see what they say. For now, this workaround is good enough.

@bdunne
Copy link
Member

bdunne commented Nov 20, 2014

Looks Good 🍰

bdunne added a commit that referenced this pull request Nov 20, 2014
…to_build_uris

Use URI to build URIs and hostname= to wrap ipv6 addresses in brackets.
@bdunne bdunne merged commit 9e87fbb into ManageIQ:master Nov 20, 2014
@jrafanie jrafanie deleted the use_uri_and_uri_hostname_equals_to_build_uris branch December 1, 2014 20:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants