http_request.rb 1.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,8 +1,11 @@
1
+ v1.1.1
2
+ * using String#each_line instead of String#each, because ruby 1.9 doesn't have the method String#each
3
+
1
4
  v1.1
2
5
  * added some testing with test/spec
3
- * fixed some bugs such as uploading files, combine parameters and query string etc.
4
- * supported the HTTP Digest Authentication
5
- * refactoring code...
6
+ * fixed some bugs such as uploading files, combine parameters and query string etc.
7
+ * supported the HTTP Digest Authentication
8
+ * refactoring code...
6
9
 
7
10
  v1.0.7
8
11
  * bug fixing for the ':ajax' and ':xhr' directive
@@ -15,16 +18,16 @@ v1.0.5
15
18
 
16
19
  v1.0.4
17
20
  * support gzipped content only if the zlib library is loaded
18
- * post xml data via the POST method
21
+ * post xml data via the POST method
19
22
 
20
23
  v1.0.3
21
24
  * add some dynamic methods such as code_1xx?, code_200?, code_403? etc. for check the http status
22
25
  * decompressing gzipped body automatically, the 'Accept-Encoding: gzip,deflate' has been added into the header for sending request automatically.
23
- * fixed retrieve cookies problem which is if a cookie name is a keyword of the cookie's info such as path, expire etc. then it doesn't work.
26
+ * fixed retrieve cookies problem which is if a cookie name is a keyword of the cookie's info such as path, expire etc. then it doesn't work.
24
27
 
25
28
  v1.0.2
26
29
  * Proc.call (block) style supported and some small changes
27
- * improve ftp protocol and add a new method get_as_string for the ftp calls
30
+ * improve ftp protocol and add a new method get_as_string for the ftp calls
28
31
 
29
32
  v1.0.1
30
33
  * new feature: upload or download files by ftp
data/README.rdoc CHANGED
@@ -227,7 +227,7 @@ download multiple files from a directory
227
227
  bug fixing, testing and testing...
228
228
 
229
229
  == LATEST VERSION
230
- 1.1
230
+ 1.1.1
231
231
 
232
232
  == Author
233
233
 
data/lib/http_request.rb CHANGED
@@ -11,9 +11,9 @@
11
11
  #
12
12
  # == Version
13
13
  #
14
- # v1.1
14
+ # v1.1.1
15
15
  #
16
- # Last Change: 04 Oct, 2009
16
+ # Last Change: 15 Oct, 2009
17
17
  #
18
18
  # == Author
19
19
  #
@@ -32,7 +32,7 @@ class HttpRequest
32
32
  include Singleton
33
33
  class << self
34
34
  # version
35
- VERSION = '1.1'.freeze
35
+ VERSION = '1.1.1'.freeze
36
36
  def version;VERSION;end
37
37
 
38
38
  # avaiabled http methods
@@ -49,7 +49,7 @@ class HttpRequest
49
49
  # update cookies
50
50
  def update_cookies(response)
51
51
  return unless response.header['set-cookie']
52
- response.header['set-cookie'].each {|k|
52
+ response.header['set-cookie'].each_line {|k|
53
53
  k, v = k.split(';')[0].split('=')
54
54
  @@__cookies[k] = v
55
55
  }
@@ -78,10 +78,10 @@ class HttpRequest
78
78
  end
79
79
 
80
80
  # send request by some given parameters
81
- def request(method, opt, &block)
81
+ def request(method, options, &block)
82
82
 
83
83
  # parse the @options
84
- parse_options(method, opt)
84
+ parse_options(method, options)
85
85
 
86
86
  # parse and merge for the options[:parameters]
87
87
  parse_parameters
@@ -96,11 +96,13 @@ class HttpRequest
96
96
  end
97
97
 
98
98
  # catch all available http requests
99
- def self.method_missing(method_name, args, &block)
99
+ def self.method_missing(method_name, options, &block)
100
+ # we need to retrieve the cookies from last http response before reset cookies if it's a Net::HTTPResponse
101
+ options[:cookies] = options[:cookies].cookies if options[:cookies].is_a? Net::HTTPResponse
100
102
  @@__cookies = {}
101
103
  method_name = method_name.to_s.downcase
102
104
  raise NoHttpMethodException, "No such http method can be called: #{method_name}" unless self.http_methods.include?(method_name)
103
- self.instance.request(method_name, args, &block)
105
+ self.instance.request(method_name, options, &block)
104
106
  end
105
107
 
106
108
  # for ftp, no plan to add new features to this method except bug fixing
@@ -250,7 +252,7 @@ class HttpRequest
250
252
 
251
253
  # support gzip
252
254
  begin; require 'zlib'; rescue LoadError; end
253
- @headers['Accept-Encoding'] = 'gzip,deflate' if defined? Zlib
255
+ @headers['Accept-Encoding'] = 'gzip,deflate' if defined? ::Zlib
254
256
 
255
257
  # ajax calls?
256
258
  @headers['X_REQUESTED_WITH'] = 'XMLHttpRequest' if @options[:ajax] or @options[:xhr]
@@ -428,7 +430,7 @@ module Net
428
430
  def body
429
431
  bd = read_body()
430
432
  return bd unless bd
431
- if (self['content-encoding'] == 'gzip') and defined?(Zlib)
433
+ if (self['content-encoding'] == 'gzip') and defined?(::Zlib)
432
434
  ::Zlib::GzipReader.new(StringIO.new(bd)).read
433
435
  else
434
436
  bd
@@ -223,6 +223,12 @@ context 'Session && Cookie' do
223
223
  h1 = hr.get(:url => URL + "/session", :cookies => h1.cookies)
224
224
  h1.body.should.equal "2"
225
225
 
226
+ h2 = hr.get(URL + "/session")
227
+ h2.body.should.equal "1"
228
+
229
+ h2 = hr.get(:url => URL + "/session", :cookies => h2)
230
+ h2.body.should.equal "2"
231
+
226
232
  h = hr.get(URL + "/session/1")
227
233
  h.body.should.equal "/session/1:/session/2"
228
234
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_request.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.1"
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - xianhua.zhou
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-04 00:00:00 +08:00
12
+ date: 2009-10-15 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15