lib/em-http/client.rb in igrigorik-em-http-request-0.1.6 vs lib/em-http/client.rb in igrigorik-em-http-request-0.1.7

- old
+ new

@@ -169,10 +169,13 @@ @content_decoder = nil end # start HTTP request once we establish connection to host def connection_completed + ssl = @options[:tls] || @options[:ssl] || {} + start_tls(ssl) if @uri.scheme == "https" or @uri.port == 443 + send_request_header send_request_body end # request is done, invoke the callback @@ -189,14 +192,22 @@ def on_error(msg) @errors = msg unbind end + def normalize_body + if @options[:body].is_a? Hash + @options[:body].to_params + else + @options[:body] + end + end + def send_request_header query = @options[:query] head = @options[:head] ? munge_header_keys(@options[:head]) : {} - body = @options[:body] + body = normalize_body # Set the Host header if it hasn't been specified already head['host'] ||= encode_host # Set the Content-Length if body is given @@ -218,14 +229,10 @@ send_data request_header end def send_request_body return unless @options[:body] - if @options[:body].is_a? Hash - body = @options[:body].to_params - else - body = @options[:body] - end + body = normalize_body send_data body end def receive_data(data) @data << data