Skip to content

Follow 302 redirects - #11

Closed
p8952 wants to merge 2 commits into
rubygems:masterfrom
p8952:302-redirect
Closed

p8952 wants to merge 2 commits into
rubygems:masterfrom
p8952:302-redirect

Conversation

@p8952

@p8952 p8952 commented Jul 9, 2013

Copy link
Copy Markdown

fixes #10, the request method was not following 302 redirects causing an HTTP status code to be returned rather than marshaled data

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 0b5cb4e on p8952:302-redirect into * on rubygems:master*.

Comment thread lib/gems/request.rb Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That is good point, I have updated the pull request.

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling c6ac76a on p8952:302-redirect into * on rubygems:master*.

Comment thread lib/gems/request.rb

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

@bf4 bf4 mentioned this pull request Jul 11, 2013
sferik added a commit that referenced this pull request Jul 12, 2013
@sferik

sferik commented Jul 12, 2013

Copy link
Copy Markdown
Member

Closed by #13.

@sferik sferik closed this Jul 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: incompatible marshal file format

4 participants