lib/http/client.rb in http-0.0.1 vs lib/http/client.rb in http-0.0.2

- old
+ new

@@ -8,11 +8,11 @@ else # Why the FUCK can't Net::HTTP do this? @uri = URI(uri) end - @options = {:response => :parsed_body}.merge(options) + @options = {:response => :object}.merge(options) end # Request a get sans response body def head(uri, options = {}) request :head, options @@ -75,26 +75,26 @@ request_class = Net::HTTP.const_get(verb.to_s.capitalize) request = request_class.new(@uri.request_uri, headers) request.set_form_data(options[:form]) if options[:form] - response = http.request(request) + net_http_response = http.request(request) + response = Http::Response.new + net_http_response.each_header do |header, value| + response[header] = value + end + response.status = Integer(net_http_response.code) # WTF again Net::HTTP + response.body = net_http_response.body + case options[:response] + when :object + response when :parsed_body - parse_response response - else + response.parse_body + when :body response.body + else raise ArgumentError, "invalid response type: #{options[:response]}" end - end - - # Parse the response body according to its content type - def parse_response(response) - if response['content-type'] - mime_type = MimeType[response['content-type'].split(/;\s*/).first] - return mime_type.parse(response.body) if mime_type - end - - response.body end end end