diff --git a/lib/httparty.rb b/lib/httparty.rb index 772ffcac..4a7529cf 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -591,6 +591,13 @@ def unlock(path, options = {}, &block) perform_request Net::HTTP::Unlock, path, options, &block end + def build_request(http_method, path, options = {}) + options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options) + HeadersProcessor.new(headers, options).call + process_cookies(options) + Request.new(http_method, path, options) + end + attr_reader :default_options private @@ -606,10 +613,7 @@ def ensure_method_maintained_across_redirects(options) end def perform_request(http_method, path, options, &block) #:nodoc: - options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options) - HeadersProcessor.new(headers, options).call - process_cookies(options) - Request.new(http_method, path, options).perform(&block) + build_request(http_method, path, options).perform(&block) end def process_cookies(options) #:nodoc: @@ -676,6 +680,10 @@ def self.head(*args, &block) def self.options(*args, &block) Basement.options(*args, &block) end + + def self.build_request(*args, &block) + Basement.build_request(*args, &block) + end end require 'httparty/hash_conversions' diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index f1181b9c..b6055298 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -970,4 +970,13 @@ def self.inherited(subclass) end.to raise_error(URI::InvalidURIError) end end + + describe "#build_request" do + it "should build a request object" do + stub_http_response_with('example.html') + request = HTTParty.build_request(Net::HTTP::Get, "http://www.example.com") + expect(request).to be_a(HTTParty::Request) + expect(request.perform.parsed_response).to eq(file_fixture('example.html')) + end + end end