em-http-request 0.2.1 → 0.2.2
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.
Potentially problematic release.
This version of em-http-request might be problematic. Click here for more details.
- data/VERSION +1 -1
- data/lib/em-http/client.rb +5 -0
- data/test/stallion.rb +5 -1
- data/test/test_request.rb +42 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/em-http/client.rb
CHANGED
@@ -256,6 +256,11 @@ module EventMachine
|
|
256
256
|
head['cookie'] = encode_cookie(cookie)
|
257
257
|
end
|
258
258
|
|
259
|
+
# Set content-type header if missing and body is a Ruby hash
|
260
|
+
if not head['content-type'] and options[:body].is_a? Hash
|
261
|
+
head['content-type'] = "application/x-www-form-urlencoded"
|
262
|
+
end
|
263
|
+
|
259
264
|
# Build the request
|
260
265
|
request_header = encode_request(@method, @uri.path, query)
|
261
266
|
request_header << encode_headers(head)
|
data/test/stallion.rb
CHANGED
@@ -87,7 +87,11 @@ Stallion.saddle :spec do |stable|
|
|
87
87
|
stable.response.status = 200
|
88
88
|
|
89
89
|
elsif stable.request.post?
|
90
|
-
|
90
|
+
if stable.request.path_info == '/echo_content_type'
|
91
|
+
stable.response.write stable.request.env["CONTENT_TYPE"]
|
92
|
+
else
|
93
|
+
stable.response.write stable.request.body.read
|
94
|
+
end
|
91
95
|
|
92
96
|
elsif stable.request.path_info == '/set_cookie'
|
93
97
|
stable.response["Set-Cookie"] = "id=1; expires=Tue, 09-Aug-2011 17:53:39 GMT; path=/;"
|
data/test/test_request.rb
CHANGED
@@ -390,4 +390,46 @@ describe EventMachine::HttpRequest do
|
|
390
390
|
}
|
391
391
|
end
|
392
392
|
end
|
393
|
+
|
394
|
+
context "body content-type encoding" do
|
395
|
+
it "should not set content type on string in body" do
|
396
|
+
EventMachine.run {
|
397
|
+
http = EventMachine::HttpRequest.new('http://127.0.0.1:8080/echo_content_type').post :body => "data"
|
398
|
+
|
399
|
+
http.errback { failed }
|
400
|
+
http.callback {
|
401
|
+
http.response_header.status.should == 200
|
402
|
+
http.response.should be_empty
|
403
|
+
EventMachine.stop
|
404
|
+
}
|
405
|
+
}
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should set content-type automatically when passed a ruby hash/array for body" do
|
409
|
+
EventMachine.run {
|
410
|
+
http = EventMachine::HttpRequest.new('http://127.0.0.1:8080/echo_content_type').post :body => {:a => :b}
|
411
|
+
|
412
|
+
http.errback { failed }
|
413
|
+
http.callback {
|
414
|
+
http.response_header.status.should == 200
|
415
|
+
http.response.should match("application/x-www-form-urlencoded")
|
416
|
+
EventMachine.stop
|
417
|
+
}
|
418
|
+
}
|
419
|
+
end
|
420
|
+
|
421
|
+
it "should not override content-type when passing in ruby hash/array for body" do
|
422
|
+
EventMachine.run {
|
423
|
+
http = EventMachine::HttpRequest.new('http://127.0.0.1:8080/echo_content_type').post({
|
424
|
+
:body => {:a => :b}, :head => {'content-type' => 'text'}})
|
425
|
+
|
426
|
+
http.errback { failed }
|
427
|
+
http.callback {
|
428
|
+
http.response_header.status.should == 200
|
429
|
+
http.response.should match("text")
|
430
|
+
EventMachine.stop
|
431
|
+
}
|
432
|
+
}
|
433
|
+
end
|
434
|
+
end
|
393
435
|
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.2
|
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: 2009-10-
|
12
|
+
date: 2009-10-29 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|