Skip to content

Commit e34a61e

Browse files
Support 'Expect: 100-continue' header by deferring sending request body until "100 Continue" response
1 parent 0945558 commit e34a61e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/em-http/client.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def send_request(head, body)
199199
@conn.send_data request_header
200200

201201
@req_body = body || (@req.file && Pathname.new(@req.file))
202-
send_request_body
202+
send_request_body unless @req.headers['expect'] == '100-continue'
203203
end
204204

205205
def on_body_data(data)
@@ -223,6 +223,10 @@ def on_decoded_body_data(data)
223223
end
224224
end
225225

226+
def request_body_pending?
227+
!!@req_body
228+
end
229+
226230
def send_request_body
227231
return if @req_body.nil?
228232

lib/em-http/http_connection.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ def peer
151151

152152
def receive_data(data)
153153
begin
154-
@p << data
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
155159
rescue HTTP::Parser::Error => e
156160
c = @clients.shift
157161
c.nil? ? unbind(e.message) : c.on_error(e.message)

0 commit comments

Comments
 (0)