Skip to content

Commit

Permalink
enable pipelining support for no-body requests (ex: HEAD) - closes ig…
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Oct 1, 2011
1 parent f81bca2 commit a1623d4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion em-http-request.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|

s.add_dependency "eventmachine", ">= 1.0.0.beta.3"
s.add_dependency "addressable", ">= 2.2.3"
s.add_dependency "http_parser.rb", ">= 0.5.2"
s.add_dependency "http_parser.rb", ">= 0.5.3"
s.add_dependency "em-socksify"
s.add_dependency "cookiejar"

Expand Down
1 change: 1 addition & 0 deletions lib/em-http/http_client_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def initialize(uri, options, method)
def follow_redirect?; @followed < @redirects; end
def http_proxy?; @proxy && [nil, :http].include?(@proxy[:type]); end
def ssl?; @uri.scheme == "https" || @uri.port == 443; end
def no_body?; @method == "HEAD"; end

def set_uri(uri)
uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s)
Expand Down
7 changes: 4 additions & 3 deletions lib/em-http/http_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def post_init
@p.header_value_type = :mixed
@p.on_headers_complete = proc do |h|
client.parse_response_header(h, @p.http_version, @p.status_code)
:reset if client.req.no_body?
end

@p.on_body = proc do |b|
Expand Down Expand Up @@ -187,8 +188,8 @@ def stream_file_data(filename, args = {})

private

def client
@clients.first
end
def client
@clients.first
end
end
end
32 changes: 30 additions & 2 deletions spec/pipelining_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
stop.call
}

pipe2.errback { p pipe2; failed(conn) }
pipe2.errback { failed(conn) }
pipe2.callback {
processed += 1
pipe2.response_header.status.should == 200
Expand All @@ -33,6 +33,34 @@

end
end

it "should perform successful pipelined HEAD requests" do
EventMachine.run do
conn = EventMachine::HttpRequest.new('http://www.igvita.com/')

pipe1 = conn.head :keepalive => true
pipe2 = conn.head :path => '/about/', :keepalive => true

processed = 0
stop = proc { EM.stop if processed == 2}

pipe1.errback { failed(conn) }
pipe1.callback {
processed += 1
pipe1.response_header.status.should == 200
stop.call
}

pipe2.errback { failed(conn) }
pipe2.callback {
processed += 1
pipe2.response_header.status.should == 200
stop.call
}

end

end
end

end
end

0 comments on commit a1623d4

Please sign in to comment.