Skip to content

Instantly share code, notes, and snippets.

@kascote
Created January 22, 2010 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kascote/283858 to your computer and use it in GitHub Desktop.
Save kascote/283858 to your computer and use it in GitHub Desktop.
response = begin
uri = URI.parse(uri)
Timeout::timeout(@timeout) {
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
http.start {
request = Net::HTTP::Get.new(uri.request_uri)
request['If-None-Match'] ||= cache['Etag']
request['If-Modified-Since'] ||= cache['Last-Modified']
request['USER-Agent'] = 'CodeAR 1.2'
request['Accept-Encoding'] = 'gzip, deflate'
http.request(request)
}
}
rescue Timeout::Error => error
Net::HTTPRequestTimeOut.new '1.1', '408', error.to_s
rescue SocketError, Errno::ECONNRESET => error
Net::HTTPInternalServerError.new '1.1', '500', error.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment