A simple HTTP client
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.textile
http.rb

README.textile

Introduction

A simple Net::HTTP based HTTP client that supports:

  • POST/GET
  • SSL/HTTPs
  • proxies
  • debugging
  • redirect handling
  • headers
  • connect and read timeout
  • detection of response encoding

Usage

  
headers = {
  "User-Agent" => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; sv-SE; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13",
  "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
}
# GET
response = HTTP.get(url, :headers => headers)

# POST
response = HTTP.post(url, :parameters => {:a => :b}, :headers => headers)

# Detect encoding
encoding = HTTP.encoding(response)

# Redirected where?
response = HTTP.get(url)
response.redirected_to

# Set proxy ignore
puts HTTP::PROXY_IGNORE
>> ['127.0.0.1', 'localhost']
HTTP::PROXY_IGNORE = ['google.com']