em-http-request 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of em-http-request might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/ext/http11_client/http11_client.c +14 -0
- data/lib/em-http/client.rb +2 -2
- data/lib/em-http/multi.rb +3 -3
- data/lib/em-http/request.rb +8 -4
- data/spec/multi_spec.rb +24 -2
- metadata +2 -2
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.7
|
@@ -21,6 +21,20 @@ static VALUE eHttpClientParserError;
|
|
21
21
|
#define id_chunk_size rb_intern("@http_chunk_size")
|
22
22
|
#define id_last_chunk rb_intern("@last_chunk")
|
23
23
|
|
24
|
+
#ifndef RHASH_TBL
|
25
|
+
/* rb_hash_lookup() is only in Ruby 1.8.7 */
|
26
|
+
static VALUE rb_hash_lookup(VALUE hash, VALUE key)
|
27
|
+
{
|
28
|
+
VALUE val;
|
29
|
+
|
30
|
+
if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
|
31
|
+
return Qnil; /* without Hash#default */
|
32
|
+
}
|
33
|
+
|
34
|
+
return val;
|
35
|
+
}
|
36
|
+
#endif
|
37
|
+
|
24
38
|
void client_http_field(void *data, const char *field, size_t flen, const char *value, size_t vlen)
|
25
39
|
{
|
26
40
|
char *ch, *end;
|
data/lib/em-http/client.rb
CHANGED
@@ -84,7 +84,7 @@ module EventMachine
|
|
84
84
|
# Escapes a URI.
|
85
85
|
def escape(s)
|
86
86
|
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
|
87
|
-
'%'+$1.unpack('H2'*$1.
|
87
|
+
'%'+$1.unpack('H2'*$1.bytesize).join('%').upcase
|
88
88
|
}.tr(' ', '+')
|
89
89
|
end
|
90
90
|
|
@@ -304,7 +304,7 @@ module EventMachine
|
|
304
304
|
|
305
305
|
else
|
306
306
|
# Set the Content-Length if body is given
|
307
|
-
head['content-length'] = body.
|
307
|
+
head['content-length'] = body.bytesize if body
|
308
308
|
|
309
309
|
# Set the cookie header if provided
|
310
310
|
if cookie = head.delete('cookie')
|
data/lib/em-http/multi.rb
CHANGED
@@ -34,10 +34,10 @@ module EventMachine
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def add(conn)
|
37
|
+
@requests.push(conn)
|
38
|
+
|
37
39
|
conn.callback { @responses[:succeeded].push(conn); check_progress }
|
38
40
|
conn.errback { @responses[:failed].push(conn); check_progress }
|
39
|
-
|
40
|
-
@requests.push(conn)
|
41
41
|
end
|
42
42
|
|
43
43
|
protected
|
@@ -48,4 +48,4 @@ module EventMachine
|
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
data/lib/em-http/request.rb
CHANGED
@@ -26,8 +26,7 @@ module EventMachine
|
|
26
26
|
|
27
27
|
attr_reader :options, :method
|
28
28
|
|
29
|
-
def initialize(host
|
30
|
-
@headers = headers
|
29
|
+
def initialize(host)
|
31
30
|
@uri = host.kind_of?(Addressable::URI) ? host : Addressable::URI::parse(host)
|
32
31
|
end
|
33
32
|
|
@@ -72,8 +71,13 @@ module EventMachine
|
|
72
71
|
|
73
72
|
# Make sure the ports are set as Addressable::URI doesn't
|
74
73
|
# set the port if it isn't there
|
75
|
-
@uri.
|
76
|
-
|
74
|
+
if @uri.scheme == "https"
|
75
|
+
@uri.port ||= 443
|
76
|
+
@port_to_connect ||= 443
|
77
|
+
else
|
78
|
+
@uri.port ||= 80
|
79
|
+
@port_to_connect ||= 80
|
80
|
+
end
|
77
81
|
|
78
82
|
@method = method.to_s.upcase
|
79
83
|
send_request(&blk)
|
data/spec/multi_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe EventMachine::MultiRequest do
|
|
14
14
|
multi.add(EventMachine::HttpRequest.new('http://0.0.0.0:8083/').get(:timeout => 1))
|
15
15
|
|
16
16
|
multi.callback {
|
17
|
-
# verify
|
17
|
+
# verify successful request
|
18
18
|
multi.responses[:succeeded].size.should == 1
|
19
19
|
multi.responses[:succeeded].first.response.should match(/test/)
|
20
20
|
|
@@ -26,4 +26,26 @@ describe EventMachine::MultiRequest do
|
|
26
26
|
}
|
27
27
|
}
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
|
+
it "should handle multiple mock requests" do
|
31
|
+
EventMachine::MockHttpRequest.register_file('http://127.0.0.1:8080/', :get, File.join(File.dirname(__FILE__), 'fixtures', 'google.ca'))
|
32
|
+
EventMachine::MockHttpRequest.register_file('http://0.0.0.0:8083/', :get, File.join(File.dirname(__FILE__), 'fixtures', 'google.ca'))
|
33
|
+
|
34
|
+
EventMachine.run {
|
35
|
+
|
36
|
+
# create an instance of multi-request handler, and the requests themselves
|
37
|
+
multi = EventMachine::MultiRequest.new
|
38
|
+
|
39
|
+
# add multiple requests to the multi-handler
|
40
|
+
multi.add(EventMachine::MockHttpRequest.new('http://127.0.0.1:8080/').get)
|
41
|
+
multi.add(EventMachine::MockHttpRequest.new('http://0.0.0.0:8083/').get)
|
42
|
+
|
43
|
+
multi.callback {
|
44
|
+
# verify successful request
|
45
|
+
multi.responses[:succeeded].size.should == 2
|
46
|
+
|
47
|
+
EventMachine.stop
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-http-request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Grigorik
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-20 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|