astro-em-http-request 0.2.3 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +42 -4
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/examples/oauth-tweet.rb +50 -0
- data/ext/http11_client/http11_client.c +27 -1
- data/lib/em-http.rb +3 -5
- data/lib/em-http/client.rb +165 -53
- data/lib/em-http/mock.rb +74 -0
- data/lib/em-http/request.rb +45 -35
- data/spec/fixtures/google.ca +21 -0
- data/spec/hash_spec.rb +24 -0
- data/spec/helper.rb +7 -0
- data/spec/mock_spec.rb +72 -0
- data/{test/test_multi.rb → spec/multi_spec.rb} +3 -3
- data/{test/test_request.rb → spec/request_spec.rb} +192 -30
- data/{test → spec}/stallion.rb +75 -8
- data/{test → spec}/stub_server.rb +0 -0
- metadata +21 -14
- data/test/helper.rb +0 -5
- data/test/test_hash.rb +0 -19
data/{test → spec}/stallion.rb
RENAMED
@@ -85,7 +85,13 @@ Stallion.saddle :spec do |stable|
|
|
85
85
|
|
86
86
|
elsif stable.request.head?
|
87
87
|
stable.response.status = 200
|
88
|
-
|
88
|
+
|
89
|
+
elsif stable.request.delete?
|
90
|
+
stable.response.status = 200
|
91
|
+
|
92
|
+
elsif stable.request.put?
|
93
|
+
stable.response.write stable.request.body.read
|
94
|
+
|
89
95
|
elsif stable.request.post?
|
90
96
|
if stable.request.path_info == '/echo_content_type'
|
91
97
|
stable.response.write stable.request.env["CONTENT_TYPE"]
|
@@ -121,15 +127,19 @@ Stallion.saddle :spec do |stable|
|
|
121
127
|
stable.response.status = 304
|
122
128
|
|
123
129
|
elsif stable.request.env["HTTP_AUTHORIZATION"]
|
124
|
-
|
125
|
-
|
126
|
-
if auth == stable.request.env["HTTP_AUTHORIZATION"]
|
130
|
+
if stable.request.path_info == '/oauth_auth'
|
127
131
|
stable.response.status = 200
|
128
|
-
stable.response.write
|
132
|
+
stable.response.write stable.request.env["HTTP_AUTHORIZATION"]
|
129
133
|
else
|
130
|
-
|
131
|
-
end
|
134
|
+
auth = "Basic %s" % Base64.encode64(['user', 'pass'].join(':')).chomp
|
132
135
|
|
136
|
+
if auth == stable.request.env["HTTP_AUTHORIZATION"]
|
137
|
+
stable.response.status = 200
|
138
|
+
stable.response.write 'success'
|
139
|
+
else
|
140
|
+
stable.response.status = 401
|
141
|
+
end
|
142
|
+
end
|
133
143
|
elsif stable.request.path_info == '/relative-location'
|
134
144
|
stable.response.status = 301
|
135
145
|
stable.response["Location"] = '/forwarded'
|
@@ -149,4 +159,61 @@ Thread.new do
|
|
149
159
|
end
|
150
160
|
end
|
151
161
|
|
152
|
-
|
162
|
+
#
|
163
|
+
# HTTP Proxy server
|
164
|
+
#
|
165
|
+
Thread.new do
|
166
|
+
server = TCPServer.new('127.0.0.1', 8082)
|
167
|
+
loop do
|
168
|
+
session = server.accept
|
169
|
+
request = ""
|
170
|
+
while (data = session.gets) != "\r\n"
|
171
|
+
request << data
|
172
|
+
end
|
173
|
+
parts = request.split("\r\n")
|
174
|
+
method, destination, http_version = parts.first.split(' ')
|
175
|
+
if method == 'CONNECT'
|
176
|
+
target_host, target_port = destination.split(':')
|
177
|
+
client = TCPSocket.open(target_host, target_port)
|
178
|
+
session.write "HTTP/1.1 200 Connection established\r\nProxy-agent: Whatever\r\n\r\n"
|
179
|
+
session.flush
|
180
|
+
|
181
|
+
content_length = -1
|
182
|
+
verb = ""
|
183
|
+
req = ""
|
184
|
+
|
185
|
+
while data = session.gets
|
186
|
+
if request = data.match(/(\w+).*HTTP\/1\.1/)
|
187
|
+
verb = request[1]
|
188
|
+
end
|
189
|
+
|
190
|
+
if post = data.match(/Content-Length: (\d+)/)
|
191
|
+
content_length = post[1].to_i
|
192
|
+
end
|
193
|
+
|
194
|
+
req += data
|
195
|
+
|
196
|
+
# read POST data
|
197
|
+
if data == "\r\n" and verb == "POST"
|
198
|
+
req += session.read(content_length)
|
199
|
+
end
|
200
|
+
|
201
|
+
if data == "\r\n"
|
202
|
+
client.write req
|
203
|
+
client.flush
|
204
|
+
client.close_write
|
205
|
+
break
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
while data = client.gets
|
210
|
+
session.write data
|
211
|
+
end
|
212
|
+
session.flush
|
213
|
+
client.close
|
214
|
+
end
|
215
|
+
session.close
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
sleep(1)
|
File without changes
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: astro-em-http-request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Grigorik
|
8
8
|
- Stephan Maka
|
9
|
+
- Julien Genestoux
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
|
13
|
-
date:
|
14
|
+
date: 2010-01-20 00:00:00 +01:00
|
14
15
|
default_executable:
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +52,7 @@ files:
|
|
51
52
|
- VERSION
|
52
53
|
- examples/fetch.rb
|
53
54
|
- examples/fibered-http.rb
|
55
|
+
- examples/oauth-tweet.rb
|
54
56
|
- ext/buffer/em_buffer.c
|
55
57
|
- ext/buffer/extconf.rb
|
56
58
|
- ext/http11_client/ext_help.h
|
@@ -63,14 +65,17 @@ files:
|
|
63
65
|
- lib/em-http/client.rb
|
64
66
|
- lib/em-http/core_ext/hash.rb
|
65
67
|
- lib/em-http/decoders.rb
|
68
|
+
- lib/em-http/mock.rb
|
66
69
|
- lib/em-http/multi.rb
|
67
70
|
- lib/em-http/request.rb
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
-
|
71
|
+
- spec/fixtures/google.ca
|
72
|
+
- spec/hash_spec.rb
|
73
|
+
- spec/helper.rb
|
74
|
+
- spec/mock_spec.rb
|
75
|
+
- spec/multi_spec.rb
|
76
|
+
- spec/request_spec.rb
|
77
|
+
- spec/stallion.rb
|
78
|
+
- spec/stub_server.rb
|
74
79
|
has_rdoc: true
|
75
80
|
homepage: http://github.com/igrigorik/em-http-request
|
76
81
|
licenses: []
|
@@ -100,11 +105,13 @@ signing_key:
|
|
100
105
|
specification_version: 3
|
101
106
|
summary: EventMachine based, async HTTP Request interface
|
102
107
|
test_files:
|
103
|
-
-
|
104
|
-
-
|
105
|
-
-
|
106
|
-
-
|
107
|
-
-
|
108
|
-
-
|
108
|
+
- spec/hash_spec.rb
|
109
|
+
- spec/helper.rb
|
110
|
+
- spec/mock_spec.rb
|
111
|
+
- spec/multi_spec.rb
|
112
|
+
- spec/request_spec.rb
|
113
|
+
- spec/stub_server.rb
|
114
|
+
- spec/stallion.rb
|
109
115
|
- examples/fibered-http.rb
|
110
116
|
- examples/fetch.rb
|
117
|
+
- examples/oauth-tweet.rb
|
data/test/helper.rb
DELETED
data/test/test_hash.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test/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.should == "a=alpha&b=beta"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should transform a more complex hash into HTTP POST Params" do
|
11
|
-
{:a => "a", :b => ["c", "d", "e"]}.to_params.should == "a=a&b[0]=c&b[1]=d&b[2]=e"
|
12
|
-
end
|
13
|
-
|
14
|
-
# Ruby 1.8 Hash is not sorted, so this test breaks randomly. Maybe once we're all on 1.9. ;-)
|
15
|
-
# it "should transform a very complex hash into HTTP POST Params" do
|
16
|
-
# {:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]}.to_params.should == "a=a&b[0][d]=d&b[0][c]=c&b[1][f]=f&b[1][e]=e"
|
17
|
-
# end
|
18
|
-
end
|
19
|
-
end
|