Project

General

Profile

Feature #11322 ยป open_uri-redirect-cookie-11322.patch

jeremyevans0 (Jeremy Evans), 08/23/2019 12:42 AM

View differences:

lib/open-uri.rb
230 230
    uri_set = {}
231 231
    buf = nil
232 232
    while true
233
      redirect = catch(:open_uri_redirect) {
233
      redirect, cookie = catch(:open_uri_redirect) {
234 234
        buf = Buffer.new
235 235
        uri.buffer_open(buf, find_proxy.call(uri), options)
236 236
        nil
......
252 252
          options = options.dup
253 253
          options.delete :http_basic_authentication
254 254
        end
255
        if cookie
256
          options = options.dup
257
          options[:cookie] = cookie.split(';')[0]
258
        end
255 259
        uri = redirect
256
        raise "HTTP redirection loop: #{uri}" if uri_set.include? uri.to_s
257
        uri_set[uri.to_s] = true
260
        raise "HTTP redirection loop: #{uri}" if uri_set.include?([uri.to_s, !!cookie])
261
        uri_set[[uri.to_s, !!cookie]] = true
258 262
      else
259 263
        break
260 264
      end
......
344 348

  
345 349
    resp = nil
346 350
    http.start {
351
      if cookie = options[:cookie]
352
        header['Cookie'] = cookie
353
      end
347 354
      req = Net::HTTP::Get.new(request_uri, header)
348 355
      if options.include? :http_basic_authentication
349 356
        user, pass = options[:http_basic_authentication]
......
382 389
      rescue URI::InvalidURIError
383 390
        raise OpenURI::HTTPError.new(io.status.join(' ') + ' (Invalid Location URI)', io)
384 391
      end
385
      throw :open_uri_redirect, loc_uri
392
      throw :open_uri_redirect, [loc_uri, resp['Set-Cookie']]
386 393
    else
387 394
      raise OpenURI::HTTPError.new(io.status.join(' '), io)
388 395
    end