HTTP to HTTPS redirection from nginx

mail@pastecode.io avatar
unknown
ruby
2 years ago
601 B
8
Indexable
Never
require 'net/http'
require 'openssl'

def fetch(url)
  uri = URI(url)
  Net::HTTP.start(uri.host, uri.port,
    :use_ssl => uri.scheme == 'https', 
    :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

    request = Net::HTTP::Get.new uri.request_uri
    request.basic_auth '<username>', '<secrect>'

    response = http.request request # Net::HTTPResponse object

    if response.is_a?(Net::HTTPRedirection)
      return fetch(response['location'])
    end
    response.body
  end
end

puts fetch('http://apik8s-devautomate2.bsstag.com/automate/sessions/f728b4423dacf76561327dced2a6337e818f0405')