diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index e818aad..67b69e2 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -432,7 +432,26 @@ module RestClient # def make_headers(user_headers) headers = stringify_headers(default_headers).merge(stringify_headers(user_headers)) - headers.merge!(@payload.headers) if @payload + + # override headers from the payload (e.g. Content-Type, Content-Length) + if @payload + payload_headers = @payload.headers + + # Warn the user if we override any headers that were previously + # present. This usually indicates that rest-client was passed + # conflicting information, e.g. if it was asked to render a payload as + # x-www-form-urlencoded but a Content-Type application/json was + # also supplied by the user. + payload_headers.each_pair do |key, val| + if headers.include?(key) + warn("warning: Overriding #{key.inspect} header " + + "#{headers.fetch(key).inspect} with #{val.inspect} " + + "due to payload") + end + end + + headers.merge!(payload_headers) + end # merge in cookies cookies = make_cookie_header