lib/flexirest/request.rb in flexirest-1.5.2 vs lib/flexirest/request.rb in flexirest-1.5.3
- old
+ new
@@ -19,10 +19,13 @@
@overridden_name = @method[:options][:overridden_name]
@object = object
@response_delegate = Flexirest::RequestDelegator.new(nil)
@params = params
@headers = HeadersList.new
+ (@method[:options][:headers] || {}).each do |k,v|
+ @headers[k] = v
+ end
@forced_url = nil
end
def object_is_class?
!@object.respond_to?(:dirty?)
@@ -461,23 +464,20 @@
end
def handle_response(response, cached = nil)
@response = response
status = @response.status || 200
+ @response.body = "{}" if @response.body.blank?
if cached && response.status == 304
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name}" +
' - Etag copy is the same as the server'
return handle_cached_response(cached)
end
if (200..399).include?(status)
- if @response.body.blank?
- @response.body = "{}"
- end
-
if @method[:options][:plain]
- return @response = Flexirest::PlainResponse.from_response(response)
+ return @response = Flexirest::PlainResponse.from_response(@response)
elsif is_json_response? || is_xml_response?
if @response.respond_to?(:proxied) && @response.proxied
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response was proxied, unable to determine size"
else
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response received #{@response.body.size} bytes"