def send_request_header
query = @options[:query]
head = @options[:head] ? munge_header_keys(@options[:head]) : {}
file = @options[:file]
proxy = @options[:proxy]
body = normalize_body
request_header = nil
if http_proxy?
head = proxy[:head] ? munge_header_keys(proxy[:head]) : {}
head['proxy-authorization'] = proxy[:authorization] if proxy[:authorization]
if @state == :connect_http_proxy
request_header = HTTP_REQUEST_HEADER % ['CONNECT', "#{@uri.host}:#{@uri.port}"]
end
end
if websocket?
head['upgrade'] = 'WebSocket'
head['connection'] = 'Upgrade'
head['origin'] = @options[:origin] || @uri.host
else
head['content-length'] = File.size(file) if file
head['content-length'] = body.bytesize if body
if cookie = head.delete('cookie')
head['cookie'] = encode_cookie(cookie)
end
if not head['content-type'] and options[:body].is_a? Hash
head['content-type'] = 'application/x-www-form-urlencoded'
end
unless options[:keepalive]
head['connection'] = 'close'
end
end
head['host'] ||= encode_host
head['user-agent'] ||= "EventMachine HttpClient"
@last_effective_url = @uri
request_header ||= encode_request(@method, @uri, query, proxy)
request_header << encode_headers(head)
request_header << CRLF
send_data request_header
end