Skip to content

Commit

Permalink
fix rfc2616 / rfc2068 conflict for 100-continue behavior, closes igri…
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Feb 20, 2011
1 parent 2512106 commit e22e948
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/em-http/client.rb
Expand Up @@ -105,6 +105,10 @@ def proxy?; !@options[:proxy].nil?; end
def http_proxy?; proxy? && [nil, :http].include?(@options[:proxy][:type]); end
def socks_proxy?; proxy? && (@options[:proxy][:type] == :socks); end

def continue?
@response_header.status == 100 && (@method == 'POST' || @method == 'PUT')
end

def build_request
head = @options[:head] ? munge_header_keys(@options[:head]) : {}
proxy = @options[:proxy]
Expand Down Expand Up @@ -132,7 +136,7 @@ def build_request
head['user-agent'] ||= "EventMachine HttpClient"

head
end
end

def send_request(head, body)
body = normalize_body(body)
Expand Down
8 changes: 5 additions & 3 deletions lib/em-http/http_connection.rb
Expand Up @@ -64,9 +64,11 @@ def post_init
end

@p.on_message_complete = proc do
c = @clients.shift
c.state = :finished
c.on_request_complete
if not @clients.first.continue?
c = @clients.shift
c.state = :finished
c.on_request_complete
end
end
end

Expand Down
27 changes: 26 additions & 1 deletion spec/external_spec.rb
Expand Up @@ -31,12 +31,37 @@

it "should handle a 100 continue" do
EventMachine.run {
# 8.2.3 Use of the 100 (Continue) Status - http://www.ietf.org/rfc/rfc2616.txt
#
# An origin server SHOULD NOT send a 100 (Continue) response if
# the request message does not include an Expect request-header
# field with the "100-continue" expectation, and MUST NOT send a
# 100 (Continue) response if such a request comes from an HTTP/1.0
# (or earlier) client. There is an exception to this rule: for
# compatibility with RFC 2068, a server MAY send a 100 (Continue)
# status in response to an HTTP/1.1 PUT or POST request that does
# not include an Expect request-header field with the "100-
# continue" expectation. This exception, the purpose of which is
# to minimize any client processing delays associated with an
# undeclared wait for 100 (Continue) status, applies only to
# HTTP/1.1 requests, and not to requests with any other HTTP-
# version value.
#
# 10.1.1: 100 Continue - http://www.ietf.org/rfc/rfc2068.txt
# The client may continue with its request. This interim response is
# used to inform the client that the initial part of the request has
# been received and has not yet been rejected by the server. The client
# SHOULD continue by sending the remainder of the request or, if the
# request has already been completed, ignore this response. The server
# MUST send a final response after the request has been completed.

url = 'http://ws.serviceobjects.com/lv/LeadValidation.asmx/ValidateLead_V2'
http = EventMachine::HttpRequest.new(url).post :body => {:name => :test}

http.errback { failed(http) }
http.callback {
http.response_header.status.should == 100
http.response_header.status.should == 500
http.response.should match('Missing')
EventMachine.stop
}
}
Expand Down

0 comments on commit e22e948

Please sign in to comment.