lib/down/net_http.rb in down-5.2.3 vs lib/down/net_http.rb in down-5.2.4

- old
+ new

@@ -156,11 +156,15 @@ raise ResponseError.new("Invalid Redirect URI: #{exception.uri}", response: response) end # forward cookies on the redirect if !exception.io.meta["set-cookie"].to_s.empty? - options["Cookie"] = exception.io.meta["set-cookie"] + options["Cookie"] ||= '' + # Add new cookies avoiding duplication + new_cookies = exception.io.meta["set-cookie"].to_s.split(',').map(&:strip) + old_cookies = options["Cookie"].split(',') + options["Cookie"] = (old_cookies | new_cookies).join(',') end follows_remaining -= 1 retry rescue OpenURI::HTTPError => exception @@ -200,17 +204,17 @@ def net_http_request(uri, options, follows_remaining:, &block) http, request = create_net_http(uri, options) begin response = http.start do - http.request(request) do |response| - unless response.is_a?(Net::HTTPRedirection) - yield response + http.request(request) do |resp| + unless resp.is_a?(Net::HTTPRedirection) + yield resp # In certain cases the caller wants to download only one portion # of the file and close the connection, so we tell Net::HTTP that # it shouldn't continue retrieving it. - response.instance_variable_set("@read", true) + resp.instance_variable_set("@read", true) end end end rescue => exception request_error!(exception) @@ -308,11 +312,11 @@ # Fortunately, the exception object holds response data that can be used to # rebuild the Net::HTTP response object. def rebuild_response_from_open_uri_exception(exception) code, message = exception.io.status - response_class = Net::HTTPResponse::CODE_TO_OBJ.fetch(code) do |code| - Net::HTTPResponse::CODE_CLASS_TO_OBJ.fetch(code[0]) do + response_class = Net::HTTPResponse::CODE_TO_OBJ.fetch(code) do |c| + Net::HTTPResponse::CODE_CLASS_TO_OBJ.fetch(c[0]) do Net::HTTPUnknownResponse end end response = response_class.new(nil, code, message)