def build_net_http_request request
headers = { 'content-type' => '', 'accept-encoding' => '' }
request.headers.each_pair do |key,value|
headers[key] = value.to_s
end
request_class = case request.http_method
when 'GET' then Net::HTTP::Get
when 'PUT' then Net::HTTP::Put
when 'POST' then Net::HTTP::Post
when 'HEAD' then Net::HTTP::Head
when 'DELETE' then Net::HTTP::Delete
else
msg = "unsupported http method: #{request.http_method}"
raise ArgumentError, msg
end
net_http_req = request_class.new(request.uri, headers)
net_http_req.body_stream = request.body_stream
net_http_req
end