Skip to content

Commit 6a711d2

Browse files
Use http_parser to parse "100 Continue" response, added spec (disabled, pending suitable test server). Rebased on iostream branch.
1 parent e34a61e commit 6a711d2

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib/em-http/http_connection.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,13 @@ def post_init
117117
@p.header_value_type = :mixed
118118
@p.on_headers_complete = proc do |h|
119119
if client
120-
client.parse_response_header(h, @p.http_version, @p.status_code)
121-
:reset if client.req.no_body?
120+
if @p.status_code == 100
121+
client.send_request_body
122+
@p.reset!
123+
else
124+
client.parse_response_header(h, @p.http_version, @p.status_code)
125+
:reset if client.req.no_body?
126+
end
122127
else
123128
# if we receive unexpected data without a pending client request
124129
# reset the parser to avoid firing any further callbacks and close
@@ -151,11 +156,7 @@ def peer
151156

152157
def receive_data(data)
153158
begin
154-
if client.request_body_pending? && data.starts_with?('HTTP/1.1 100 Continue')
155-
client.send_request_body
156-
else
157-
@p << data
158-
end
159+
@p << data
159160
rescue HTTP::Parser::Error => e
160161
c = @clients.shift
161162
c.nil? ? unbind(e.message) : c.on_error(e.message)

spec/client_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,19 @@ def failed(http=nil)
256256
}
257257
end
258258

259+
xit "should support expect-continue header" do
260+
EventMachine.run {
261+
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090').post :body => "data", :head => { 'expect' => '100-continue' }
262+
263+
http.errback { failed(http) }
264+
http.callback {
265+
http.response_header.status.should == 200
266+
http.response.should == "data"
267+
EventMachine.stop
268+
}
269+
}
270+
end
271+
259272
it "should perform successful GET with custom header" do
260273
EventMachine.run {
261274
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/').get :head => {'if-none-match' => 'evar!'}

0 commit comments

Comments
 (0)