Conversation
|
Changes Unknown when pulling 0b5cb4e on p8952:302-redirect into * on rubygems:master*. |
There was a problem hiding this comment.
Why is the host hardcoded to https://bundler.rubygems.org? Shouldn't it use the Location header from the response, as specified in RFC 2616?
There was a problem hiding this comment.
That is good point, I have updated the pull request.
|
Changes Unknown when pulling c6ac76a on p8952:302-redirect into * on rubygems:master*. |
There was a problem hiding this comment.
The response['location'] will be a fully qualified URI, not just the host part. And the path could be completely different than in the initial request.
If you want me to merge this, you need to add some specs to prove that it works as expected.
There was a problem hiding this comment.
It should have something like
RequestError = Class.new(StandardError)
BadUrl = Class.new(RequestError)
def url_to_uri(url)
begin
uri = URI.parse(url)
rescue URI::InvalidURIError, SocketError => e
raise BadUrl.new(e)
end
end
uri = url_to_uri(response['location'])
path = uri.path # or uri.request_uri to include the query
host = uri.host
though this won't handle meta content refresh
I would separate out the actual connection.request code to avoid too much recursion
As an aside, I see you're not handling all the Net:HTTP errors
HTTP_ERRORS = [Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError]
I have elsewhere done something like
BadResponse = Class.new(RequestError)
BasicResponse = Struct.new('BasicResponse', :url, :code)
def get_response(url)
uri = url_to_uri(url)
Net::HTTP.get_response(uri)
rescue EOFError => e
BasicResponse.new(url, '200')
rescue *HTTP_ERRORS => e
log url.inspect + e.inspect
raise BadResponse.new(e)
end
Also, why VERIFY_NONE ? just add require 'net/https' right?
|
Closed by #13. |
fixes #10, the request method was not following 302 redirects causing an HTTP status code to be returned rather than marshaled data