em-http-request 0.2.10 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ ## 0.2.14 / 2010-10-06
4
+
5
+ - bugfix: form-encode keys/values of ruby objects passed in as body
6
+
7
+ ## 0.2.13 / 2010-09-25
8
+
9
+ - added SOCKS5 proxy support
10
+ - bugfix: follow redirects on HEAD requests
11
+
12
+ ## 0.2.12 / 2010-09-12
13
+
14
+ - added headers callback (http.headers {|h| p h})
15
+ - added .close method on client obj to terminate session (accepts message)
16
+
17
+ - bugfix: report 0 for response status on 1.9 on timeouts
18
+ - bugfix: handle bad Location host redirects
19
+ - bugfix: reset host override on connect
20
+
21
+ ## 0.2.11 / 2010-08-16
22
+
23
+ - all URIs are now normalized prior to dispatch (and on redirect)
24
+ - default to direct proxy (instead of CONNECT handshake) - better performance
25
+ - specify :proxy => {:tunnel => true} if you need to force CONNECT route
26
+ - MultiRequest accepts block syntax for dispatching parallel requests (see specs)
27
+ - MockHttpRequest accepts block syntax (see Mock wiki page)
28
+
29
+
30
+ - bugfix: nullbyte frame for websockets
31
+ - bugfix: set @uri on DNS resolve failure
32
+ - bugfix: handle bad hosts in absolute redirects
33
+ - bugfix: reset seen content on redirects (doh!)
34
+ - bugfix: invalid multibyte escape in websocket regex (1.9.2+)
35
+ - bugfix: report etag and last_modified headers correctly
36
+
data/LICENSE CHANGED
@@ -1,58 +1,58 @@
1
- Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
2
- You can redistribute it and/or modify it under either the terms of the GPL
3
- (see COPYING.txt file), or the conditions below:
4
-
5
- 1. You may make and give away verbatim copies of the source form of the
6
- software without restriction, provided that you duplicate all of the
7
- original copyright notices and associated disclaimers.
8
-
9
- 2. You may modify your copy of the software in any way, provided that
10
- you do at least ONE of the following:
11
-
12
- a) place your modifications in the Public Domain or otherwise
13
- make them Freely Available, such as by posting said
14
- modifications to Usenet or an equivalent medium, or by allowing
15
- the author to include your modifications in the software.
16
-
17
- b) use the modified software only within your corporation or
18
- organization.
19
-
20
- c) rename any non-standard executables so the names do not conflict
21
- with standard executables, which must also be provided.
22
-
23
- d) make other distribution arrangements with the author.
24
-
25
- 3. You may distribute the software in object code or executable
26
- form, provided that you do at least ONE of the following:
27
-
28
- a) distribute the executables and library files of the software,
29
- together with instructions (in the manual page or equivalent)
30
- on where to get the original distribution.
31
-
32
- b) accompany the distribution with the machine-readable source of
33
- the software.
34
-
35
- c) give non-standard executables non-standard names, with
36
- instructions on where to get the original software distribution.
37
-
38
- d) make other distribution arrangements with the author.
39
-
40
- 4. You may modify and include the part of the software into any other
41
- software (possibly commercial). But some files in the distribution
42
- are not written by the author, so that they are not under this terms.
43
-
44
- They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45
- files under the ./missing directory. See each file for the copying
46
- condition.
47
-
48
- 5. The scripts and library files supplied as input to or produced as
49
- output from the software do not automatically fall under the
50
- copyright of the software, but belong to whomever generated them,
51
- and may be sold commercially, and may be aggregated with this
52
- software.
53
-
54
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
- PURPOSE.
58
-
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the GPL
3
+ (see COPYING.txt file), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict
21
+ with standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable
26
+ form, provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard executables non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under this terms.
43
+
44
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45
+ files under the ./missing directory. See each file for the copying
46
+ condition.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
58
+
data/README.md ADDED
@@ -0,0 +1,168 @@
1
+ EM-HTTP-Request
2
+ ===============
3
+
4
+ Asynchronous HTTP client for Ruby, based on EventMachine runtime.
5
+
6
+ - Ragel HTTP parser for speed & performance
7
+ - Simple interface for single & parallel requests via deferred callbacks
8
+ - Automatic gzip & deflate decoding
9
+ - Basic-Auth & OAuth support
10
+ - Custom timeout support
11
+ - Stream response processing
12
+ - Proxy support (with SSL Tunneling): CONNECT, direct & SOCKS5
13
+ - Auto-follow 3xx redirects with custom max depth
14
+ - Bi-directional communication with web-socket services
15
+ - [Native mocking support](http://wiki.github.com/igrigorik/em-http-request/mocking-httprequest) and through [Webmock](http://github.com/bblimke/webmock)
16
+
17
+ Getting started
18
+ ---------------
19
+
20
+ gem install em-http-request
21
+ irb:0> require 'em-http'
22
+
23
+ Or checkout [screencast / demo](http://everburning.com/news/eventmachine-screencast-em-http-request/) of using EM-HTTP-Request.
24
+
25
+ Libraries & Applications using em-http
26
+ --------------------------------------
27
+
28
+ - [chirpstream](http://github.com/joshbuddy/chirpstream) - EM client for Twitters Chirpstream API
29
+ - [RDaneel](http://github.com/hasmanydevelopers/RDaneel) - Ruby crawler which respects robots.txt
30
+ - [rsolr-async](http://github.com/mwmitchell/rsolr-async) - An asynchronus connection adapter for RSolr
31
+ - [PubSubHubbub](http://github.com/igrigorik/PubSubHubbub) - Asynchronous PubSubHubbub ruby client
32
+ - [Firering](http://github.com/EmmanuelOga/firering) - Eventmachine powered Campfire API
33
+ - and many others.. drop me a link if you want yours included!
34
+
35
+ Simple client example
36
+ ---------------------
37
+
38
+ EventMachine.run {
39
+ http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}, :timeout => 10
40
+
41
+ http.callback {
42
+ p http.response_header.status
43
+ p http.response_header
44
+ p http.response
45
+
46
+ EventMachine.stop
47
+ }
48
+ }
49
+
50
+ Multi-request example
51
+ ---------------------
52
+
53
+ Fire and wait for multiple requests to complete via the MultiRequest interface.
54
+
55
+ EventMachine.run {
56
+ multi = EventMachine::MultiRequest.new
57
+
58
+ # add multiple requests to the multi-handler
59
+ multi.add(EventMachine::HttpRequest.new('http://www.google.com/').get)
60
+ multi.add(EventMachine::HttpRequest.new('http://www.yahoo.com/').get)
61
+
62
+ multi.callback {
63
+ p multi.responses[:succeeded]
64
+ p multi.responses[:failed]
65
+
66
+ EventMachine.stop
67
+ }
68
+ }
69
+
70
+ Basic-Auth example
71
+ ------------------
72
+
73
+ Full basic author support. For OAuth, check examples/oauth-tweet.rb file.
74
+
75
+ EventMachine.run {
76
+ http = EventMachine::HttpRequest.new('http://www.website.com/').get :head => {'authorization' => ['user', 'pass']}
77
+
78
+ http.errback { failed }
79
+ http.callback {
80
+ p http.response_header
81
+ EventMachine.stop
82
+ }
83
+ }
84
+
85
+
86
+ POSTing data example
87
+ --------------------
88
+
89
+ EventMachine.run {
90
+ http1 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => {"key1" => 1, "key2" => [2,3]}
91
+ http2 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => "some data"
92
+
93
+ # ...
94
+ }
95
+
96
+ Streaming body processing
97
+ -------------------------
98
+
99
+ Allows you to consume an HTTP stream of content in real-time. Each time a new piece of content is pushed
100
+ to the client, it is passed to the stream callback for you to operate on.
101
+
102
+ EventMachine.run {
103
+ http = EventMachine::HttpRequest.new('http://www.website.com/').get
104
+ http.stream { |chunk| print chunk }
105
+ }
106
+
107
+ Streaming files from disk
108
+ -------------------------
109
+ Allows you to efficiently stream a (large) file from disk via EventMachine's FileStream interface.
110
+
111
+ EventMachine.run {
112
+ http = EventMachine::HttpRequest.new('http://www.website.com/').post :file => 'largefile.txt'
113
+ http.callback { |chunk| puts "Upload finished!" }
114
+ }
115
+
116
+ Proxy example
117
+ -------------
118
+ Full transparent proxy support with support for SSL tunneling.
119
+
120
+ EventMachine.run {
121
+ http = EventMachine::HttpRequest.new('http://www.website.com/').get :proxy => {
122
+ :host => 'www.myproxy.com',
123
+ :port => 8080,
124
+ :authorization => ['username', 'password'] # authorization is optional
125
+ }
126
+
127
+ SOCKS5 Proxy example
128
+ -------------
129
+ Tunnel your requests via connect via SOCKS5 proxies (ssh -D port somehost).
130
+
131
+ EventMachine.run {
132
+ http = EventMachine::HttpRequest.new('http://www.website.com/').get :proxy => {
133
+ :host => 'www.myproxy.com',
134
+ :port => 8080,
135
+ :type => :socks
136
+ }
137
+
138
+ Auto-follow 3xx redirects
139
+ -------------------------
140
+
141
+ Specify the max depth of redirects to follow, default is 0.
142
+
143
+ EventMachine.run {
144
+ http = EventMachine::HttpRequest.new('http://www.google.com/').get :redirects => 1
145
+ http.callback { p http.last_effective_url }
146
+ }
147
+
148
+ WebSocket example
149
+ -----------------
150
+
151
+ [Bi-directional communication with WebSockets](http://www.igvita.com/2009/12/22/ruby-websockets-tcp-for-the-browser/): simply pass in a ws:// resource and the client will negotiate the connection upgrade for you. On successful handshake the callback is invoked, and any incoming messages will be passed to the stream callback. The client can also send data to the server at will by calling the "send" method!
152
+
153
+ EventMachine.run {
154
+ http = EventMachine::HttpRequest.new("ws://yourservice.com/websocket").get :timeout => 0
155
+
156
+ http.errback { puts "oops" }
157
+ http.callback {
158
+ puts "WebSocket connected!"
159
+ http.send("Hello client")
160
+ }
161
+
162
+ http.stream { |msg|
163
+ puts "Recieved: #{msg}"
164
+ http.send "Pong: #{msg}"
165
+ }
166
+
167
+ http.disconnect { puts "oops, dropped connection?" }
168
+ }
data/Rakefile CHANGED
@@ -19,9 +19,9 @@ task :default => :compile
19
19
  Rake::RDocTask.new(:rdoc) do |task|
20
20
  task.rdoc_dir = 'doc'
21
21
  task.title = 'EventMachine::HttpRequest'
22
- task.options = %w(--title HttpRequest --main README --line-numbers)
22
+ task.options = %w(--title HttpRequest --main README.md --line-numbers)
23
23
  task.rdoc_files.include(['lib/**/*.rb'])
24
- task.rdoc_files.include(['README', 'LICENSE'])
24
+ task.rdoc_files.include(['README.md', 'LICENSE'])
25
25
  end
26
26
 
27
27
  # Rebuild parser Ragel
@@ -34,8 +34,12 @@ task :ragel do
34
34
  end
35
35
  end
36
36
 
37
- task :spec do
38
- sh 'spec spec/*_spec.rb'
37
+ require 'spec'
38
+ require 'spec/rake/spectask'
39
+ Spec::Rake::SpecTask.new(:spec) do |t|
40
+ t.spec_opts ||= []
41
+ t.spec_opts << "--options" << "spec/spec.opts"
42
+ t.spec_files = FileList['spec/**/*_spec.rb']
39
43
  end
40
44
 
41
45
  def make(makedir)
@@ -48,7 +52,7 @@ end
48
52
 
49
53
  def setup_extension(dir, extension)
50
54
  ext = "ext/#{dir}"
51
- ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
55
+ ext_so = "#{ext}/#{extension}.#{Config::MAKEFILE_CONFIG['DLEXT']}"
52
56
  ext_files = FileList[
53
57
  "#{ext}/*.c",
54
58
  "#{ext}/*.h",
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.10
1
+ 0.2.14
@@ -5,28 +5,30 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{em-http-request}
8
- s.version = "0.2.10"
8
+ s.version = "0.2.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ilya Grigorik"]
12
- s.date = %q{2010-07-07}
12
+ s.date = %q{2010-10-06}
13
13
  s.description = %q{EventMachine based, async HTTP Request interface}
14
14
  s.email = %q{ilya@igvita.com}
15
15
  s.extensions = ["ext/buffer/extconf.rb", "ext/http11_client/extconf.rb"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
- "README.rdoc"
18
+ "README.md"
19
19
  ]
20
20
  s.files = [
21
21
  ".gitignore",
22
+ "Changelog.md",
22
23
  "LICENSE",
23
- "README.rdoc",
24
+ "README.md",
24
25
  "Rakefile",
25
26
  "VERSION",
26
27
  "em-http-request.gemspec",
27
28
  "examples/fetch.rb",
28
29
  "examples/fibered-http.rb",
29
30
  "examples/oauth-tweet.rb",
31
+ "examples/socks5.rb",
30
32
  "examples/websocket-handler.rb",
31
33
  "examples/websocket-server.rb",
32
34
  "ext/buffer/em_buffer.c",
@@ -41,18 +43,18 @@ Gem::Specification.new do |s|
41
43
  "lib/em-http.rb",
42
44
  "lib/em-http/client.rb",
43
45
  "lib/em-http/core_ext/bytesize.rb",
44
- "lib/em-http/core_ext/hash.rb",
45
46
  "lib/em-http/decoders.rb",
46
47
  "lib/em-http/http_options.rb",
47
48
  "lib/em-http/mock.rb",
48
49
  "lib/em-http/multi.rb",
49
50
  "lib/em-http/request.rb",
51
+ "spec/encoding_spec.rb",
50
52
  "spec/fixtures/google.ca",
51
- "spec/hash_spec.rb",
52
53
  "spec/helper.rb",
53
54
  "spec/mock_spec.rb",
54
55
  "spec/multi_spec.rb",
55
56
  "spec/request_spec.rb",
57
+ "spec/spec.opts",
56
58
  "spec/stallion.rb",
57
59
  "spec/stub_server.rb"
58
60
  ]
@@ -61,10 +63,10 @@ Gem::Specification.new do |s|
61
63
  s.require_paths = ["lib"]
62
64
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
63
65
  s.rubyforge_project = %q{em-http-request}
64
- s.rubygems_version = %q{1.3.6}
66
+ s.rubygems_version = %q{1.3.7}
65
67
  s.summary = %q{EventMachine based, async HTTP Request interface}
66
68
  s.test_files = [
67
- "spec/hash_spec.rb",
69
+ "spec/encoding_spec.rb",
68
70
  "spec/helper.rb",
69
71
  "spec/mock_spec.rb",
70
72
  "spec/multi_spec.rb",
@@ -74,6 +76,7 @@ Gem::Specification.new do |s|
74
76
  "examples/fetch.rb",
75
77
  "examples/fibered-http.rb",
76
78
  "examples/oauth-tweet.rb",
79
+ "examples/socks5.rb",
77
80
  "examples/websocket-handler.rb",
78
81
  "examples/websocket-server.rb"
79
82
  ]
@@ -82,7 +85,7 @@ Gem::Specification.new do |s|
82
85
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
83
86
  s.specification_version = 3
84
87
 
85
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
88
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
86
89
  s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.9"])
87
90
  s.add_runtime_dependency(%q<addressable>, [">= 2.0.0"])
88
91
  else
data/examples/fetch.rb CHANGED
@@ -1,30 +1,30 @@
1
- require 'rubygems'
2
- require 'eventmachine'
3
- require '../lib/em-http'
4
-
5
- urls = ARGV
6
- if urls.size < 1
7
- puts "Usage: #{$0} <url> <url> <...>"
8
- exit
9
- end
10
-
11
- pending = urls.size
12
-
13
- EM.run do
14
- urls.each do |url|
15
- http = EM::HttpRequest.new(url).get
16
- http.callback {
17
- puts "#{url}\n#{http.response_header.status} - #{http.response.length} bytes\n"
18
- puts http.response
19
-
20
- pending -= 1
21
- EM.stop if pending < 1
22
- }
23
- http.errback {
24
- puts "#{url}\n" + http.error
25
-
26
- pending -= 1
27
- EM.stop if pending < 1
28
- }
29
- end
30
- end
1
+ require 'rubygems'
2
+ require 'eventmachine'
3
+ require '../lib/em-http'
4
+
5
+ urls = ARGV
6
+ if urls.size < 1
7
+ puts "Usage: #{$0} <url> <url> <...>"
8
+ exit
9
+ end
10
+
11
+ pending = urls.size
12
+
13
+ EM.run do
14
+ urls.each do |url|
15
+ http = EM::HttpRequest.new(url).get
16
+ http.callback {
17
+ puts "#{url}\n#{http.response_header.status} - #{http.response.length} bytes\n"
18
+ puts http.response
19
+
20
+ pending -= 1
21
+ EM.stop if pending < 1
22
+ }
23
+ http.errback {
24
+ puts "#{url}\n" + http.error
25
+
26
+ pending -= 1
27
+ EM.stop if pending < 1
28
+ }
29
+ end
30
+ end
@@ -1,39 +1,39 @@
1
- require 'eventmachine'
2
- require 'em-http'
3
- require 'fiber'
4
-
5
- # Using Fibers in Ruby 1.9 to simulate blocking IO / IO scheduling
6
- # while using the async EventMachine API's
7
-
8
- def async_fetch(url)
9
- f = Fiber.current
10
- http = EventMachine::HttpRequest.new(url).get :timeout => 10
11
-
12
- http.callback { f.resume(http) }
13
- http.errback { f.resume(http) }
14
-
15
- return Fiber.yield
16
- end
17
-
18
- EventMachine.run do
19
- Fiber.new{
20
-
21
- puts "Setting up HTTP request #1"
22
- data = async_fetch('http://www.google.com/')
23
- puts "Fetched page #1: #{data.response_header.status}"
24
-
25
- puts "Setting up HTTP request #2"
26
- data = async_fetch('http://www.yahoo.com/')
27
- puts "Fetched page #2: #{data.response_header.status}"
28
-
29
- EventMachine.stop
30
- }.resume
31
- end
32
-
33
- puts "Done"
34
-
35
- # Setting up HTTP request #1
36
- # Fetched page #1: 302
37
- # Setting up HTTP request #2
38
- # Fetched page #2: 200
1
+ require 'eventmachine'
2
+ require 'em-http'
3
+ require 'fiber'
4
+
5
+ # Using Fibers in Ruby 1.9 to simulate blocking IO / IO scheduling
6
+ # while using the async EventMachine API's
7
+
8
+ def async_fetch(url)
9
+ f = Fiber.current
10
+ http = EventMachine::HttpRequest.new(url).get :timeout => 10
11
+
12
+ http.callback { f.resume(http) }
13
+ http.errback { f.resume(http) }
14
+
15
+ return Fiber.yield
16
+ end
17
+
18
+ EventMachine.run do
19
+ Fiber.new{
20
+
21
+ puts "Setting up HTTP request #1"
22
+ data = async_fetch('http://www.google.com/')
23
+ puts "Fetched page #1: #{data.response_header.status}"
24
+
25
+ puts "Setting up HTTP request #2"
26
+ data = async_fetch('http://www.yahoo.com/')
27
+ puts "Fetched page #2: #{data.response_header.status}"
28
+
29
+ EventMachine.stop
30
+ }.resume
31
+ end
32
+
33
+ puts "Done"
34
+
35
+ # Setting up HTTP request #1
36
+ # Fetched page #1: 302
37
+ # Setting up HTTP request #2
38
+ # Fetched page #2: 200
39
39
  # Done