Sha256: d1ea5a9aac9e93cf7e1a6609090d4c9397ff50efb291cfffb795b555279dacbc

Contents?: true

Size: 495 Bytes

Versions: 2

Compression:

Stored size: 495 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
    rescue Timeout::Error, Errno::ENETUNREACH, Errno::ETIMEDOUT, SocketError
      raise LongURL::NetworkError
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
jakimowicz-longurl-0.0.4 lib/longurl/direct.rb
longurl-0.0.4 lib/longurl/direct.rb