simplehttp 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS CHANGED
@@ -1 +1,2 @@
1
1
  Tim Becker (tim@kuriositaet.de)
2
+ Minero Aoki (setup.rb)
data/CHANGELOG CHANGED
@@ -0,0 +1,5 @@
1
+ = Fri Feb 9 12:23:20 CET 2007
2
+ * easier access to response headers
3
+ * pass through headers during redirects
4
+ * more tests and documentation
5
+ * included `setup.rb`
data/README CHANGED
@@ -1,10 +1,30 @@
1
- SimpleHttp - a simplified wrapper around Net::Http
1
+ = SimpleHttp - a simplified wrapper around Net::Http
2
2
 
3
3
  SimpleHttp aims to reduce the complexity of Net::Http while providing
4
4
  the most commonly used (by me) http functionality.
5
5
 
6
+ INSTALLATION
7
+
8
+ * Using +gem+
9
+
10
+ gem install simple_http
11
+
12
+ * Using +setup.rb+
13
+
14
+ ruby setup.rb config
15
+ ruby setup.rb install
16
+
17
+ * tarball and zip packages are available from
18
+ RubyForge[http://rubyforge.org/projects/simplehttp/]
19
+
20
+
21
+
6
22
  FEATURES / USAGE
7
23
 
24
+ * Require the lib:
25
+
26
+ require 'simple_http'
27
+
8
28
  * No fuss one line GET and POST requests:
9
29
 
10
30
  str = SimpleHttp.get "http://www.example.com"
@@ -40,7 +60,9 @@ FEATURES / USAGE
40
60
 
41
61
  * Access headers of the request or response
42
62
  http = SimpleHttp.new "www.example.com"
43
- http.request_header["X-Custom-Header"]="useful header"
63
+ http.request_headers["X-Custom-Header"]="useful header"
64
+ http.get
65
+ puts "server set cookie: #{http.response_headers['set-cookie']}"
44
66
 
45
67
  * Automatically follows Http Redirects.
46
68
 
data/Rakefile CHANGED
@@ -98,7 +98,7 @@ RubyForgeUser="a2800276"
98
98
  RubyForgeProject=PROJECT_NAME
99
99
 
100
100
  desc "Upload the web pages to the web."
101
- task :upload_pages => ["rdoc", "clean"] do
101
+ task :upload_pages => ["clean", :rdoc] do
102
102
  if RubyForgeProject then
103
103
  path = "/var/www/gforge-projects/#{RubyForgeProject}"
104
104
  sh "scp -r doc/html/* #{RubyForgeUser}@rubyforge.org:#{path}"
@@ -42,15 +42,21 @@ require 'base64'
42
42
  # sh.get
43
43
  class SimpleHttp
44
44
 
45
- VERSION='0.1.0'
45
+ VERSION='0.1.1'
46
46
 
47
- attr_accessor :proxy_host, :proxy_port, :proxy_user, :proxy_pwd, :uri, :request_headers, :response_handlers, :follow_num_redirects
47
+ attr_accessor :proxy_host, :proxy_port, :proxy_user, :proxy_pwd, :uri, :request_headers, :response_headers, :response_handlers, :follow_num_redirects
48
48
 
49
49
  RESPONSE_HANDLERS = {
50
50
  Net::HTTPResponse => lambda { |request, response, http|
51
+ response.each_header {|key, value|
52
+ http.response_headers[key]=value
53
+ }
51
54
  raise response.to_s
52
55
  },
53
56
  Net::HTTPSuccess => lambda { |request, response, http|
57
+ response.each_header {|key, value|
58
+ http.response_headers[key]=value
59
+ }
54
60
  return response.body
55
61
  },
56
62
  Net::HTTPRedirection => lambda { |request, response, http|
@@ -66,6 +72,10 @@ class SimpleHttp
66
72
  # request in case they were non standard.
67
73
  sh.response_handlers = http.response_handlers
68
74
 
75
+ # copy the request headers
76
+ sh.request_headers=http.request_headers
77
+ sh.response_headers=http.response_headers
78
+
69
79
  # http doesn't permit redirects for methods
70
80
  # other than GET of HEAD, so we complain in case
71
81
  # we get them in response to a POST request. (Or
@@ -110,6 +120,7 @@ class SimpleHttp
110
120
 
111
121
 
112
122
  @request_headers={}
123
+ @response_headers={}
113
124
  @response_handlers=RESPONSE_HANDLERS.clone
114
125
  @follow_num_redirects=3
115
126
 
@@ -48,6 +48,7 @@ class SimpleHttpTest < Test::Unit::TestCase
48
48
  ret = SimpleHttp.get uri, "query" => "query_test"
49
49
  assert_equal("query_test", ret, "basic GET (query) 4.1 test failed.");
50
50
 
51
+
51
52
  end
52
53
 
53
54
  # Tests for http GET calls implemented using instantiated SimpleHttp objects.
@@ -69,13 +70,26 @@ class SimpleHttpTest < Test::Unit::TestCase
69
70
  ret = http.get "query2" => "query_test"
70
71
  assert_equal("query_test", ret, "basic GET (query) 3 test failed.")
71
72
 
72
- # GET requst with a custom request_header
73
+ # GET request with a custom request_header
73
74
  http = SimpleHttp.new "http://127.0.0.1:12345/header_test"
74
75
  http.request_headers= {'x-special-http-header'=>'my-value'}
75
76
  ret = http.get
76
77
  assert_equal("my-value", ret, "GET header test 4")
77
78
 
78
-
79
+ # GET test with custom response_headers
80
+ http = SimpleHttp.new "http://127.0.0.1:12345/header_test"
81
+ http.request_headers= {'x-special-http-header'=>'resp-header-test'}
82
+ http.get
83
+ assert_equal("resp-header-test", http.response_headers['x-special-response'], "GET response header test 5")
84
+
85
+ # GET test with custom request & response header and redirect
86
+ # test that request headers we set remain intact during redirects.
87
+
88
+ http = SimpleHttp.new "http://127.0.0.1:12345/redirect_special_header"
89
+ http.request_headers["x-special-http-header"]='redirect_test'
90
+ http.get
91
+ assert_equal("redirect_test", http.response_headers['x-special-response'], "GET response header redirect test. 6")
92
+
79
93
  end
80
94
 
81
95
  # http POST calls using class methods.
@@ -52,6 +52,7 @@ class TestServer
52
52
  # return value of request header named "X-Special-Http-Header"
53
53
  @server.mount_proc("/header_test"){|req, res|
54
54
  res.body=req.header["x-special-http-header"][0]
55
+ res['x-special-response']=req.header["x-special-http-header"][0]
55
56
  }
56
57
 
57
58
  # return value of request header named "X-Special-Http-Header"
@@ -86,5 +87,10 @@ class TestServer
86
87
  res.status=301
87
88
  res.header['location']="http://127.0.0.1:12345/test1"
88
89
  }
90
+
91
+ @server.mount_proc("/redirect_special_header") { |req, res|
92
+ res.status=301
93
+ res.header['location']="http://127.0.0.1:12345/header_test"
94
+ }
89
95
  end
90
96
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: simplehttp
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-02-08 00:00:00 +01:00
6
+ version: 0.1.1
7
+ date: 2007-02-09 00:00:00 +01:00
8
8
  summary: "simple_http: Simple Http client lib."
9
9
  require_paths:
10
10
  - lib