Permalink
Browse files

fix path override in redirects, closes #230

  • Loading branch information...
1 parent 88705dc commit ff935e8dca0dcb50428a2f6edb7c4aa4a3f12dc0 @igrigorik igrigorik committed Apr 19, 2013
Showing with 23 additions and 8 deletions.
  1. +1 −1 lib/em-http/client.rb
  2. +6 −5 lib/em-http/http_client_options.rb
  3. +2 −2 spec/pipelining_spec.rb
  4. +14 −0 spec/redirect_spec.rb
View
@@ -133,7 +133,7 @@ def normalize_body(body)
def build_request
head = @req.headers ? munge_header_keys(@req.headers) : {}
-
+
if @conn.connopts.http_proxy?
proxy = @conn.connopts.proxy
head['proxy-authorization'] = proxy[:authorization] if proxy[:authorization]
@@ -11,29 +11,30 @@ def initialize(uri, options, method)
@followed = options[:followed] ||= 0 # keep track of number of followed requests
@method = method.to_s.upcase
- @headers = options[:head] || {}
+ @headers = options[:head] || {}
@query = options[:query]
- @path = options[:path]
+
@file = options[:file]
@body = options[:body]
@pass_cookies = options.fetch(:pass_cookies, true) # pass cookies between redirects
@decoding = options.fetch(:decoding, true) # auto-decode compressed response
- set_uri(uri)
+ set_uri(uri, options[:path])
end
def follow_redirect?; @followed < @redirects; end
def ssl?; @uri.scheme == "https" || @uri.port == 443; end
def no_body?; @method == "HEAD"; end
- def set_uri(uri)
+ def set_uri(uri, path = nil)
uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s)
+ uri.path = path if path
uri.path = '/' if uri.path.empty?
- uri.path = @path if @path
@uri = uri
+ @path = uri.path
# Make sure the ports are set as Addressable::URI doesn't
# set the port if it isn't there
View
@@ -27,7 +27,7 @@
pipe2.callback {
processed += 1
pipe2.response_header.status.should == 200
- pipe2.response.should match(/2011/i)
+ pipe2.response.should match(/html/i)
stop.call
}
@@ -63,4 +63,4 @@
end
end
-end
+end
View
@@ -248,6 +248,20 @@ def response(r)
}
end
+ it "should follow location redirects with path" do
+ EventMachine.run {
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect').get :path => '/redirect', :redirects => 1
+ http.errback { failed(http) }
+ http.callback {
+ http.last_effective_url.to_s.should == 'http://127.0.0.1:8090/gzip'
+ http.response_header.status.should == 200
+ http.redirects.should == 1
+
+ EM.stop
+ }
+ }
+ end
+
it "should call middleware each time it redirects" do
EventMachine.run {
conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/middleware_redirects_1')

0 comments on commit ff935e8

Please sign in to comment.