Sha256: 04747ac9f3dfa43468055057d69e2a75971cd7208f87e1a1e30c928cad644946

Contents?: true

Size: 384 Bytes

Versions: 6

Compression:

Stored size: 384 Bytes

Contents

require 'uri'
require "net/http"

module LongURL
  module Direct
    def self.follow_redirections(orig)
      uri = URI.parse(orig)
      Net::HTTP.start(uri.host, uri.port) do |http|
        answer = http.get(uri.path.empty? ? '/' : uri.path)
        dest = answer['Location']
        (dest && dest[0, 7] == 'http://' && follow_redirections(dest)) || orig
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
jakimowicz-longurl-0.0.1 lib/longurl/direct.rb
jakimowicz-longurl-0.0.2 lib/longurl/direct.rb
jakimowicz-longurl-0.0.3 lib/longurl/direct.rb
longurl-0.0.2 lib/longurl/direct.rb
longurl-0.0.3 lib/longurl/direct.rb
longurl-0.0.1 lib/longurl/direct.rb