Permalink
Browse files

easier access to response headers, pass through headers during redire…

…cts, more tests and documentation,	included `setup.rb`

git-svn-id: svn+ssh://rubyforge.org/var/svn/simplehttp/trunk@4 0af4886c-b8f6-4d8a-922d-87859854324b
  • Loading branch information...
1 parent dbc80a4 commit 9cd2efaddaad4d0f62e927b5d8d2dbcbbf94de69 a2800276 committed Feb 9, 2007
Showing with 1,650 additions and 6 deletions.
  1. +1 −0 AUTHORS
  2. +5 −0 CHANGELOG
  3. +24 −2 README
  4. +13 −2 lib/simple_http.rb
  5. +1,585 −0 setup.rb
  6. +16 −2 test/http_test.rb
  7. +6 −0 test/http_test_server.rb
View
@@ -1 +1,2 @@
Tim Becker (tim@kuriositaet.de)
+Minero Aoki (setup.rb)
View
@@ -0,0 +1,5 @@
+= Fri Feb 9 12:23:20 CET 2007
+* easier access to response headers
+* pass through headers during redirects
+* more tests and documentation
+* included `setup.rb`
View
@@ -1,10 +1,30 @@
-SimpleHttp - a simplified wrapper around Net::Http
+= SimpleHttp - a simplified wrapper around Net::Http
SimpleHttp aims to reduce the complexity of Net::Http while providing
the most commonly used (by me) http functionality.
+INSTALLATION
+
+* Using +gem+
+
+ gem install simple_http
+
+* Using +setup.rb+
+
+ ruby setup.rb config
+ ruby setup.rb install
+
+* tarball and zip packages are available from
+ RubyForge[http://rubyforge.org/projects/simplehttp/]
+
+
+
FEATURES / USAGE
+* Require the lib:
+
+ require 'simple_http'
+
* No fuss one line GET and POST requests:
str = SimpleHttp.get "http://www.example.com"
@@ -40,7 +60,9 @@ FEATURES / USAGE
* Access headers of the request or response
http = SimpleHttp.new "www.example.com"
- http.request_header["X-Custom-Header"]="useful header"
+ http.request_headers["X-Custom-Header"]="useful header"
+ http.get
+ puts "server set cookie: #{http.response_headers['set-cookie']}"
* Automatically follows Http Redirects.
View
@@ -42,15 +42,21 @@
# sh.get
class SimpleHttp
- VERSION='0.1.0'
+ VERSION='0.1.1'
- attr_accessor :proxy_host, :proxy_port, :proxy_user, :proxy_pwd, :uri, :request_headers, :response_handlers, :follow_num_redirects
+ attr_accessor :proxy_host, :proxy_port, :proxy_user, :proxy_pwd, :uri, :request_headers, :response_headers, :response_handlers, :follow_num_redirects
RESPONSE_HANDLERS = {
Net::HTTPResponse => lambda { |request, response, http|
+ response.each_header {|key, value|
+ http.response_headers[key]=value
+ }
raise response.to_s
},
Net::HTTPSuccess => lambda { |request, response, http|
+ response.each_header {|key, value|
+ http.response_headers[key]=value
+ }
return response.body
},
Net::HTTPRedirection => lambda { |request, response, http|
@@ -66,6 +72,10 @@ class SimpleHttp
# request in case they were non standard.
sh.response_handlers = http.response_handlers
+ # copy the request headers
+ sh.request_headers=http.request_headers
+ sh.response_headers=http.response_headers
+
# http doesn't permit redirects for methods
# other than GET of HEAD, so we complain in case
# we get them in response to a POST request. (Or
@@ -110,6 +120,7 @@ def initialize uri
@request_headers={}
+ @response_headers={}
@response_handlers=RESPONSE_HANDLERS.clone
@follow_num_redirects=3
Oops, something went wrong. Retry.

0 comments on commit 9cd2efa

Please sign in to comment.