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 +36 -0
- data/LICENSE +58 -58
- data/README.md +168 -0
- data/Rakefile +9 -5
- data/VERSION +1 -1
- data/em-http-request.gemspec +12 -9
- data/examples/fetch.rb +30 -30
- data/examples/fibered-http.rb +38 -38
- data/examples/oauth-tweet.rb +49 -49
- data/examples/socks5.rb +26 -0
- data/examples/websocket-handler.rb +28 -28
- data/examples/websocket-server.rb +8 -8
- data/ext/buffer/extconf.rb +53 -53
- data/ext/http11_client/ext_help.h +14 -14
- data/ext/http11_client/extconf.rb +6 -6
- data/ext/http11_client/http11_client.c +328 -328
- data/ext/http11_client/http11_parser.c +418 -418
- data/ext/http11_client/http11_parser.h +48 -48
- data/ext/http11_client/http11_parser.rl +170 -170
- data/lib/em-http/client.rb +268 -42
- data/lib/em-http/http_options.rb +4 -2
- data/lib/em-http/mock.rb +90 -50
- data/lib/em-http/multi.rb +21 -17
- data/lib/em-http/request.rb +1 -0
- data/lib/em-http.rb +20 -19
- data/spec/encoding_spec.rb +34 -0
- data/spec/fixtures/google.ca +20 -21
- data/spec/helper.rb +3 -2
- data/spec/mock_spec.rb +79 -34
- data/spec/multi_spec.rb +27 -10
- data/spec/request_spec.rb +301 -68
- data/spec/spec.opts +7 -0
- data/spec/stallion.rb +64 -3
- data/spec/stub_server.rb +22 -22
- metadata +16 -9
- data/README.rdoc +0 -138
- data/lib/em-http/core_ext/hash.rb +0 -53
- data/spec/hash_spec.rb +0 -24
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 2
|
|
8
|
-
-
|
|
9
|
-
version: 0.2.
|
|
8
|
+
- 14
|
|
9
|
+
version: 0.2.14
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Ilya Grigorik
|
|
@@ -14,13 +14,14 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2010-
|
|
17
|
+
date: 2010-10-06 00:00:00 -04:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: eventmachine
|
|
22
22
|
prerelease: false
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
24
25
|
requirements:
|
|
25
26
|
- - ">="
|
|
26
27
|
- !ruby/object:Gem::Version
|
|
@@ -35,6 +36,7 @@ dependencies:
|
|
|
35
36
|
name: addressable
|
|
36
37
|
prerelease: false
|
|
37
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
38
40
|
requirements:
|
|
39
41
|
- - ">="
|
|
40
42
|
- !ruby/object:Gem::Version
|
|
@@ -54,17 +56,19 @@ extensions:
|
|
|
54
56
|
- ext/http11_client/extconf.rb
|
|
55
57
|
extra_rdoc_files:
|
|
56
58
|
- LICENSE
|
|
57
|
-
- README.
|
|
59
|
+
- README.md
|
|
58
60
|
files:
|
|
59
61
|
- .gitignore
|
|
62
|
+
- Changelog.md
|
|
60
63
|
- LICENSE
|
|
61
|
-
- README.
|
|
64
|
+
- README.md
|
|
62
65
|
- Rakefile
|
|
63
66
|
- VERSION
|
|
64
67
|
- em-http-request.gemspec
|
|
65
68
|
- examples/fetch.rb
|
|
66
69
|
- examples/fibered-http.rb
|
|
67
70
|
- examples/oauth-tweet.rb
|
|
71
|
+
- examples/socks5.rb
|
|
68
72
|
- examples/websocket-handler.rb
|
|
69
73
|
- examples/websocket-server.rb
|
|
70
74
|
- ext/buffer/em_buffer.c
|
|
@@ -79,18 +83,18 @@ files:
|
|
|
79
83
|
- lib/em-http.rb
|
|
80
84
|
- lib/em-http/client.rb
|
|
81
85
|
- lib/em-http/core_ext/bytesize.rb
|
|
82
|
-
- lib/em-http/core_ext/hash.rb
|
|
83
86
|
- lib/em-http/decoders.rb
|
|
84
87
|
- lib/em-http/http_options.rb
|
|
85
88
|
- lib/em-http/mock.rb
|
|
86
89
|
- lib/em-http/multi.rb
|
|
87
90
|
- lib/em-http/request.rb
|
|
91
|
+
- spec/encoding_spec.rb
|
|
88
92
|
- spec/fixtures/google.ca
|
|
89
|
-
- spec/hash_spec.rb
|
|
90
93
|
- spec/helper.rb
|
|
91
94
|
- spec/mock_spec.rb
|
|
92
95
|
- spec/multi_spec.rb
|
|
93
96
|
- spec/request_spec.rb
|
|
97
|
+
- spec/spec.opts
|
|
94
98
|
- spec/stallion.rb
|
|
95
99
|
- spec/stub_server.rb
|
|
96
100
|
has_rdoc: true
|
|
@@ -103,6 +107,7 @@ rdoc_options:
|
|
|
103
107
|
require_paths:
|
|
104
108
|
- lib
|
|
105
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
|
+
none: false
|
|
106
111
|
requirements:
|
|
107
112
|
- - ">="
|
|
108
113
|
- !ruby/object:Gem::Version
|
|
@@ -112,6 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
112
117
|
- 6
|
|
113
118
|
version: 1.8.6
|
|
114
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
|
+
none: false
|
|
115
121
|
requirements:
|
|
116
122
|
- - ">="
|
|
117
123
|
- !ruby/object:Gem::Version
|
|
@@ -121,12 +127,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
121
127
|
requirements: []
|
|
122
128
|
|
|
123
129
|
rubyforge_project: em-http-request
|
|
124
|
-
rubygems_version: 1.3.
|
|
130
|
+
rubygems_version: 1.3.7
|
|
125
131
|
signing_key:
|
|
126
132
|
specification_version: 3
|
|
127
133
|
summary: EventMachine based, async HTTP Request interface
|
|
128
134
|
test_files:
|
|
129
|
-
- spec/
|
|
135
|
+
- spec/encoding_spec.rb
|
|
130
136
|
- spec/helper.rb
|
|
131
137
|
- spec/mock_spec.rb
|
|
132
138
|
- spec/multi_spec.rb
|
|
@@ -136,5 +142,6 @@ test_files:
|
|
|
136
142
|
- examples/fetch.rb
|
|
137
143
|
- examples/fibered-http.rb
|
|
138
144
|
- examples/oauth-tweet.rb
|
|
145
|
+
- examples/socks5.rb
|
|
139
146
|
- examples/websocket-handler.rb
|
|
140
147
|
- examples/websocket-server.rb
|
data/README.rdoc
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
= EM-HTTP-Client
|
|
2
|
-
|
|
3
|
-
EventMachine based HTTP Request interface. Supports streaming response processing, uses Ragel HTTP parser.
|
|
4
|
-
- Simple interface for single & parallel requests via deferred callbacks
|
|
5
|
-
- Automatic gzip & deflate decoding
|
|
6
|
-
- Basic-Auth & OAuth support
|
|
7
|
-
- Custom timeouts
|
|
8
|
-
- Proxy support (with SSL Tunneling)
|
|
9
|
-
- Auto-follow 3xx redirects with max depth
|
|
10
|
-
- Bi-directional communication with web-socket services
|
|
11
|
-
|
|
12
|
-
Screencast / Demo of using EM-HTTP-Request:
|
|
13
|
-
- http://everburning.com/news/eventmachine-screencast-em-http-request/
|
|
14
|
-
|
|
15
|
-
== Getting started
|
|
16
|
-
|
|
17
|
-
# install & configure gemcutter repos
|
|
18
|
-
gem update --system
|
|
19
|
-
gem install gemcutter
|
|
20
|
-
gem tumble
|
|
21
|
-
|
|
22
|
-
gem install em-http-request
|
|
23
|
-
|
|
24
|
-
irb:0> require 'em-http'
|
|
25
|
-
|
|
26
|
-
== Simple client example
|
|
27
|
-
|
|
28
|
-
EventMachine.run {
|
|
29
|
-
http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}, :timeout => 10
|
|
30
|
-
|
|
31
|
-
http.callback {
|
|
32
|
-
p http.response_header.status
|
|
33
|
-
p http.response_header
|
|
34
|
-
p http.response
|
|
35
|
-
|
|
36
|
-
EventMachine.stop
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
== Multi request example
|
|
41
|
-
Fire and wait for multiple requess to complete via the MultiRequest interface.
|
|
42
|
-
|
|
43
|
-
EventMachine.run {
|
|
44
|
-
multi = EventMachine::MultiRequest.new
|
|
45
|
-
|
|
46
|
-
# add multiple requests to the multi-handler
|
|
47
|
-
multi.add(EventMachine::HttpRequest.new('http://www.google.com/').get)
|
|
48
|
-
multi.add(EventMachine::HttpRequest.new('http://www.yahoo.com/').get)
|
|
49
|
-
|
|
50
|
-
multi.callback {
|
|
51
|
-
p multi.responses[:succeeded]
|
|
52
|
-
p multi.responses[:failed]
|
|
53
|
-
|
|
54
|
-
EventMachine.stop
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
== Basic-Auth example
|
|
59
|
-
Full basic author support. For OAuth, check examples/oauth-tweet.rb file.
|
|
60
|
-
|
|
61
|
-
EventMachine.run {
|
|
62
|
-
http = EventMachine::HttpRequest.new('http://www.website.com/').get :head => {'authorization' => ['user', 'pass']}
|
|
63
|
-
|
|
64
|
-
http.errback { failed }
|
|
65
|
-
http.callback {
|
|
66
|
-
p http.response_header
|
|
67
|
-
EventMachine.stop
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
== POST example
|
|
73
|
-
EventMachine.run {
|
|
74
|
-
http1 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => {"key1" => 1, "key2" => [2,3]}
|
|
75
|
-
http2 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => "some data"
|
|
76
|
-
|
|
77
|
-
# ...
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
== Streaming body processing
|
|
81
|
-
Allows you to consume an HTTP stream of content in real-time. Each time a new piece of conent is pushed
|
|
82
|
-
to the client, it is passed to the stream callback for you to operate on.
|
|
83
|
-
|
|
84
|
-
EventMachine.run {
|
|
85
|
-
http = EventMachine::HttpRequest.new('http://www.website.com/').get
|
|
86
|
-
http.stream { |chunk| print chunk }
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
== Streaming file from disk
|
|
90
|
-
Allows you to efficiently stream a (large) file from disk via EventMachine's FileStream interface.
|
|
91
|
-
|
|
92
|
-
EventMachine.run {
|
|
93
|
-
http = EventMachine::HttpRequest.new('http://www.website.com/').post :file => 'largefile.txt'
|
|
94
|
-
http.callback { |chunk| puts "Upload finished!" }
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
== Proxy example
|
|
98
|
-
Full transparent proxy support with support for SSL tunneling.
|
|
99
|
-
|
|
100
|
-
EventMachine.run {
|
|
101
|
-
http = EventMachine::HttpRequest.new('http://www.website.com/').get :proxy => {
|
|
102
|
-
:host => 'www.myproxy.com',
|
|
103
|
-
:port => 8080,
|
|
104
|
-
:authorization => ['username', 'password'] # authorization is optional
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
== Auto-follow 3xx redirects
|
|
108
|
-
Specify the max depth of redirects to follow, default is 0.
|
|
109
|
-
|
|
110
|
-
EventMachine.run {
|
|
111
|
-
http = EventMachine::HttpRequest.new('http://www.google.com/').get :redirects => 1
|
|
112
|
-
http.callback { p http.last_effective_url }
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
== WebSocket example
|
|
117
|
-
Bi-directional communication with WebSockets: simply pass in a ws:// resource and the client will
|
|
118
|
-
negotiate the connection upgrade for you. On successfull handshake the callback is invoked, and
|
|
119
|
-
any incoming messages will be passed to the stream callback. The client can also send data to the
|
|
120
|
-
server at will by calling the "send" method!
|
|
121
|
-
- http://www.igvita.com/2009/12/22/ruby-websockets-tcp-for-the-browser/
|
|
122
|
-
|
|
123
|
-
EventMachine.run {
|
|
124
|
-
http = EventMachine::HttpRequest.new("ws://yourservice.com/websocket").get :timeout => 0
|
|
125
|
-
|
|
126
|
-
http.errback { puts "oops" }
|
|
127
|
-
http.callback {
|
|
128
|
-
puts "WebSocket connected!"
|
|
129
|
-
http.send("Hello client")
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
http.stream { |msg|
|
|
133
|
-
puts "Recieved: #{msg}"
|
|
134
|
-
http.send "Pong: #{msg}"
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
http.disconnect { puts "oops, dropped connection?" }
|
|
138
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
class Hash
|
|
2
|
-
# Stolen partially from Merb : http://noobkit.com/show/ruby/gems/development/merb/hash/to_params.html
|
|
3
|
-
# Convert this hash to a query string:
|
|
4
|
-
#
|
|
5
|
-
# { :name => "Bob",
|
|
6
|
-
# :address => {
|
|
7
|
-
# :street => '111 Ruby Ave.',
|
|
8
|
-
# :city => 'Ruby Central',
|
|
9
|
-
# :phones => ['111-111-1111', '222-222-2222']
|
|
10
|
-
# }
|
|
11
|
-
# }.to_params
|
|
12
|
-
# #=> "name=Bob&address[city]=Ruby Central&address[phones]=111-111-1111222-222-2222&address[street]=111 Ruby Ave."
|
|
13
|
-
#
|
|
14
|
-
def to_params
|
|
15
|
-
params = ''
|
|
16
|
-
stack = []
|
|
17
|
-
|
|
18
|
-
each do |k, v|
|
|
19
|
-
if v.is_a?(Hash)
|
|
20
|
-
stack << [k,v]
|
|
21
|
-
elsif v.is_a?(Array)
|
|
22
|
-
stack << [k,Hash.from_array(v)]
|
|
23
|
-
else
|
|
24
|
-
params << "#{k}=#{v}&"
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
stack.each do |parent, hash|
|
|
29
|
-
hash.each do |k, v|
|
|
30
|
-
if v.is_a?(Hash)
|
|
31
|
-
stack << ["#{parent}[#{k}]", v]
|
|
32
|
-
else
|
|
33
|
-
params << "#{parent}[#{k}]=#{v}&"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
params.chop! # trailing &
|
|
39
|
-
params
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
##
|
|
43
|
-
# Builds a hash from an array with keys as array indices.
|
|
44
|
-
def self.from_array(array = [])
|
|
45
|
-
h = Hash.new
|
|
46
|
-
array.size.times do |t|
|
|
47
|
-
h[t] = array[t]
|
|
48
|
-
end
|
|
49
|
-
h
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
data/spec/hash_spec.rb
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require 'spec/helper'
|
|
2
|
-
|
|
3
|
-
describe Hash do
|
|
4
|
-
|
|
5
|
-
describe ".to_params" do
|
|
6
|
-
it "should transform a basic hash into HTTP POST Params" do
|
|
7
|
-
{:a => "alpha", :b => "beta"}.to_params.split("&").should include "a=alpha"
|
|
8
|
-
{:a => "alpha", :b => "beta"}.to_params.split("&").should include "b=beta"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "should transform a more complex hash into HTTP POST Params" do
|
|
12
|
-
{:a => "a", :b => ["c", "d", "e"]}.to_params.split("&").should include "a=a"
|
|
13
|
-
{:a => "a", :b => ["c", "d", "e"]}.to_params.split("&").should include "b[0]=c"
|
|
14
|
-
{:a => "a", :b => ["c", "d", "e"]}.to_params.split("&").should include "b[1]=d"
|
|
15
|
-
{:a => "a", :b => ["c", "d", "e"]}.to_params.split("&").should include "b[2]=e"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should transform a very complex hash into HTTP POST Params" do
|
|
19
|
-
params = {:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]}.to_params.split("&")
|
|
20
|
-
params.should include "a=a"
|
|
21
|
-
params.should include "b[0][d]=d"
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|