rack-client 0.3.0 → 0.3.1.pre.a
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +12 -14
- data/lib/rack/client/adapter/base.rb +23 -14
- data/lib/rack/client/adapter/base.rbc +1802 -0
- data/lib/rack/client/adapter/simple.rb +53 -21
- data/lib/rack/client/adapter/simple.rbc +2063 -0
- data/lib/rack/client/adapter.rbc +225 -0
- data/lib/rack/client/{dual_band.rb → core/dual_band.rb} +0 -0
- data/lib/rack/client/core/dual_band.rbc +380 -0
- data/lib/rack/client/{headers.rb → core/headers.rb} +1 -1
- data/lib/rack/client/core/headers.rbc +1811 -0
- data/lib/rack/client/core/response.rb +50 -0
- data/lib/rack/client/core/response.rbc +1105 -0
- data/lib/rack/client/core.rb +3 -0
- data/lib/rack/client/core.rbc +85 -0
- data/lib/rack/client/handler/em-http.rb +3 -7
- data/lib/rack/client/handler/em-http.rbc +1648 -0
- data/lib/rack/client/handler/excon.rb +6 -14
- data/lib/rack/client/handler/excon.rbc +1270 -0
- data/lib/rack/client/handler/net_http.rb +7 -4
- data/lib/rack/client/handler/net_http.rbc +2400 -0
- data/lib/rack/client/handler/typhoeus.rb +12 -5
- data/lib/rack/client/handler/typhoeus.rbc +1885 -0
- data/lib/rack/client/handler.rbc +340 -0
- data/lib/rack/client/{auth → middleware/auth}/abstract/challenge.rb +0 -0
- data/lib/rack/client/middleware/auth/abstract/challenge.rbc +1453 -0
- data/lib/rack/client/{auth → middleware/auth}/basic.rb +0 -0
- data/lib/rack/client/middleware/auth/basic.rbc +1566 -0
- data/lib/rack/client/{auth → middleware/auth}/digest/challenge.rb +0 -0
- data/lib/rack/client/middleware/auth/digest/challenge.rbc +1124 -0
- data/lib/rack/client/{auth → middleware/auth}/digest/md5.rb +0 -0
- data/lib/rack/client/middleware/auth/digest/md5.rbc +2241 -0
- data/lib/rack/client/{auth → middleware/auth}/digest/params.rb +0 -0
- data/lib/rack/client/middleware/auth/digest/params.rbc +365 -0
- data/lib/rack/client/middleware/auth.rb +5 -0
- data/lib/rack/client/middleware/auth.rbc +117 -0
- data/lib/rack/client/{cache → middleware/cache}/cachecontrol.rb +0 -0
- data/lib/rack/client/middleware/cache/cachecontrol.rbc +1610 -0
- data/lib/rack/client/{cache → middleware/cache}/context.rb +12 -3
- data/lib/rack/client/middleware/cache/context.rbc +2074 -0
- data/lib/rack/client/{cache → middleware/cache}/entitystore.rb +0 -0
- data/lib/rack/client/middleware/cache/entitystore.rbc +1619 -0
- data/lib/rack/client/{cache → middleware/cache}/key.rb +0 -0
- data/lib/rack/client/middleware/cache/key.rbc +1217 -0
- data/lib/rack/client/{cache → middleware/cache}/metastore.rb +0 -0
- data/lib/rack/client/middleware/cache/metastore.rbc +2754 -0
- data/lib/rack/client/{cache → middleware/cache}/options.rb +0 -0
- data/lib/rack/client/middleware/cache/options.rbc +1844 -0
- data/lib/rack/client/{cache → middleware/cache}/request.rb +0 -0
- data/lib/rack/client/middleware/cache/request.rbc +1020 -0
- data/lib/rack/client/{cache → middleware/cache}/response.rb +19 -0
- data/lib/rack/client/middleware/cache/response.rbc +1540 -0
- data/lib/rack/client/{cache → middleware/cache}/storage.rb +0 -0
- data/lib/rack/client/middleware/cache/storage.rbc +1106 -0
- data/lib/rack/client/middleware/cache.rb +19 -0
- data/lib/rack/client/middleware/cache.rbc +528 -0
- data/lib/rack/client/{cookie_jar → middleware/cookie_jar}/context.rb +0 -0
- data/lib/rack/client/middleware/cookie_jar/context.rbc +1576 -0
- data/lib/rack/client/{cookie_jar → middleware/cookie_jar}/cookie.rb +0 -0
- data/lib/rack/client/middleware/cookie_jar/cookie.rbc +2393 -0
- data/lib/rack/client/{cookie_jar → middleware/cookie_jar}/cookiestore.rb +0 -0
- data/lib/rack/client/middleware/cookie_jar/cookiestore.rbc +1209 -0
- data/lib/rack/client/{cookie_jar → middleware/cookie_jar}/options.rb +0 -0
- data/lib/rack/client/middleware/cookie_jar/options.rbc +1305 -0
- data/lib/rack/client/{cookie_jar → middleware/cookie_jar}/request.rb +0 -0
- data/lib/rack/client/middleware/cookie_jar/request.rbc +568 -0
- data/lib/rack/client/{cookie_jar → middleware/cookie_jar}/response.rb +0 -0
- data/lib/rack/client/middleware/cookie_jar/response.rbc +616 -0
- data/lib/rack/client/{cookie_jar → middleware/cookie_jar}/storage.rb +0 -0
- data/lib/rack/client/middleware/cookie_jar/storage.rbc +894 -0
- data/lib/rack/client/middleware/cookie_jar.rb +17 -0
- data/lib/rack/client/middleware/cookie_jar.rbc +471 -0
- data/lib/rack/client/{follow_redirects.rb → middleware/follow_redirects.rb} +0 -0
- data/lib/rack/client/middleware/follow_redirects.rbc +1344 -0
- data/lib/rack/client/middleware.rb +4 -0
- data/lib/rack/client/middleware.rbc +101 -0
- data/lib/rack/client/parser/base.rbc +898 -0
- data/lib/rack/client/parser/body_collection.rbc +1220 -0
- data/lib/rack/client/parser/context.rbc +540 -0
- data/lib/rack/client/parser/request.rbc +631 -0
- data/lib/rack/client/parser/response.rbc +663 -0
- data/lib/rack/client/parser.rbc +484 -0
- data/lib/rack/client/version.rb +1 -1
- data/lib/rack/client/version.rbc +203 -0
- data/lib/rack/client.rb +3 -13
- data/lib/rack/client.rbc +701 -0
- data/spec/core/headers_spec.rb +47 -0
- data/spec/core/headers_spec.rbc +1674 -0
- data/spec/core/response_spec.rb +78 -0
- data/spec/core/response_spec.rbc +2244 -0
- data/spec/handler/em_http_spec.rb +4 -19
- data/spec/handler/em_http_spec.rbc +224 -0
- data/spec/handler/excon_spec.rb +4 -4
- data/spec/handler/excon_spec.rbc +224 -0
- data/spec/handler/net_http_spec.rb +7 -4
- data/spec/handler/net_http_spec.rbc +307 -0
- data/spec/handler/typhoeus_spec.rb +6 -17
- data/spec/handler/typhoeus_spec.rbc +307 -0
- data/spec/helpers/async_helper.rb +31 -0
- data/spec/helpers/async_helper.rbc +843 -0
- data/spec/helpers/em_http_helper.rb +24 -0
- data/spec/helpers/em_http_helper.rbc +663 -0
- data/spec/helpers/excon_helper.rb +13 -0
- data/spec/helpers/excon_helper.rbc +461 -0
- data/spec/helpers/handler_helper.rb +68 -0
- data/spec/helpers/handler_helper.rbc +1769 -0
- data/spec/helpers/net_http_helper.rb +26 -0
- data/spec/helpers/net_http_helper.rbc +806 -0
- data/spec/helpers/sync_helper.rb +9 -0
- data/spec/helpers/sync_helper.rbc +311 -0
- data/spec/helpers/typhoeus_helper.rb +32 -0
- data/spec/helpers/typhoeus_helper.rbc +936 -0
- data/spec/middleware/cache_spec.rb +25 -0
- data/spec/middleware/cache_spec.rbc +712 -0
- data/spec/middleware/cookie_jar_spec.rb +19 -0
- data/spec/middleware/cookie_jar_spec.rbc +614 -0
- data/spec/middleware/etag_spec.rb +10 -0
- data/spec/middleware/etag_spec.rbc +438 -0
- data/spec/middleware/follow_redirects_spec.rb +12 -0
- data/spec/middleware/follow_redirects_spec.rbc +402 -0
- data/spec/middleware/lint_spec.rb +10 -0
- data/spec/middleware/lint_spec.rbc +392 -0
- data/spec/shared/handler_api.rb +33 -0
- data/spec/shared/handler_api.rbc +1340 -0
- data/spec/shared/streamed_response_api.rb +14 -0
- data/spec/shared/streamed_response_api.rbc +508 -0
- data/spec/spec_apps/cache.ru +14 -0
- data/spec/spec_apps/cookie.ru +12 -0
- data/spec/spec_apps/delete.ru +10 -0
- data/spec/spec_apps/get.ru +13 -0
- data/spec/spec_apps/head.ru +10 -0
- data/spec/spec_apps/hello_world.ru +1 -0
- data/spec/spec_apps/redirect.ru +13 -0
- data/spec/spec_apps/stream.ru +9 -0
- data/spec/spec_config.ru +10 -0
- data/spec/spec_helper.rb +14 -12
- metadata +190 -64
- data/lib/rack/client/cache.rb +0 -19
- data/lib/rack/client/cookie_jar.rb +0 -17
- data/lib/rack/client/response.rb +0 -9
- data/spec/apps/example.org.ru +0 -128
- data/spec/auth/basic_spec.rb +0 -69
- data/spec/auth/digest/md5_spec.rb +0 -69
- data/spec/cache_spec.rb +0 -40
- data/spec/cookie_jar_spec.rb +0 -37
- data/spec/endpoint_spec.rb +0 -30
- data/spec/follow_redirect_spec.rb +0 -27
- data/spec/handler/async_api_spec.rb +0 -69
- data/spec/handler/sync_api_spec.rb +0 -55
- data/spec/middleware_helper.rb +0 -37
- data/spec/middleware_spec.rb +0 -53
- data/spec/parser/json_spec.rb +0 -22
- data/spec/parser/yaml_spec.rb +0 -22
- data/spec/server_helper.rb +0 -72
data/spec/cookie_jar_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe Rack::Client::CookieJar do
|
4
|
-
let(:client) do
|
5
|
-
Rack::Client.new("http://localhost:#{server.port}") do
|
6
|
-
use Rack::Client::CookieJar
|
7
|
-
run Rack::Client::Handler::NetHTTP
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'Synchronous API' do
|
12
|
-
it 'serves the cookie in future responses' do
|
13
|
-
response = client.get("http://localhost:#{server.port}/cookied")
|
14
|
-
response['Set-Cookie'].should_not be_nil
|
15
|
-
response['rack-client-cookiejar.cookies'].should_not be_nil
|
16
|
-
|
17
|
-
response = client.get("http://localhost:#{server.port}/cookied")
|
18
|
-
response['Set-Cookie'].should be_nil
|
19
|
-
response['rack-client-cookiejar.cookies'].should_not be_nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'Asynchronous API' do
|
24
|
-
it 'serves the cookie in future responses' do
|
25
|
-
client.get("http://localhost:#{server.port}/cookied") do |response|
|
26
|
-
response['Set-Cookie'].should_not be_nil
|
27
|
-
response['rack-client-cookiejar.cookies'].should_not be_nil
|
28
|
-
|
29
|
-
client.get("http://localhost:#{server.port}/cookied") do |response|
|
30
|
-
response['Set-Cookie'].should be_nil
|
31
|
-
response['rack-client-cookiejar.cookies'].should_not be_nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
data/spec/endpoint_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
require 'sinatra/base'
|
4
|
-
|
5
|
-
class MyApp < Sinatra::Base
|
6
|
-
get "/awesome" do
|
7
|
-
"test"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Rack::Client, "with an Rack app endpoint" do
|
12
|
-
let(:client) do
|
13
|
-
Rack::Client.new("http://localhost:#{server.port}") do
|
14
|
-
run Rack::URLMap.new("http://example.org/" => MyApp)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "with a custom domain" do
|
19
|
-
it "returns the body" do
|
20
|
-
response = client.get("http://example.org/awesome")
|
21
|
-
response.status.should == 200
|
22
|
-
response.body.to_s.should == "test"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "only functions for that domain" do
|
26
|
-
response = client.get("http://example.org/")
|
27
|
-
response.status.should == 404
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe Rack::Client::FollowRedirects do
|
4
|
-
let(:client) do
|
5
|
-
Rack::Client.new("http://localhost:#{server.port}") do
|
6
|
-
use Rack::Client::FollowRedirects
|
7
|
-
run Rack::Client::Handler::NetHTTP
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'Synchronous API' do
|
12
|
-
it "follows redirects" do
|
13
|
-
response = client.get("http://localhost:#{server.port}/redirect")
|
14
|
-
response.status.should == 200
|
15
|
-
response.body.to_s.should == "after redirect"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'Asynchronous API' do
|
20
|
-
it "follows redirects" do
|
21
|
-
client.get("http://localhost:#{server.port}/redirect") do |response|
|
22
|
-
response.status.should == 200
|
23
|
-
response.body.to_s.should == "after redirect"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
share_examples_for "Asynchronous Request API" do
|
4
|
-
context 'DELETE request' do
|
5
|
-
it 'can handle a No Content response' do
|
6
|
-
client.delete("/shelf/ctm") do |response|
|
7
|
-
response.status.should == 204
|
8
|
-
finish
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'GET request' do
|
14
|
-
it 'has the proper response for a basic request' do
|
15
|
-
client.get("/ping") do |response|
|
16
|
-
response.status.should == 200
|
17
|
-
response.body.to_s.should == 'pong'
|
18
|
-
response["Content-Type"].should == 'text/html'
|
19
|
-
response["Content-Length"].to_i.should == 4
|
20
|
-
finish
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'can handle a temporary redirect response' do
|
25
|
-
client.get("/redirect") do |response|
|
26
|
-
response.status.should == 302
|
27
|
-
response["Location"].should == "/after-redirect"
|
28
|
-
finish
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'can return an empty body' do
|
33
|
-
client.get("/empty") do |response|
|
34
|
-
response.body.should be_empty
|
35
|
-
finish
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'HEAD request' do
|
41
|
-
it 'can handle ETag headers' do
|
42
|
-
client.head("/shelf") do |response|
|
43
|
-
response.status.should == 200
|
44
|
-
response["ETag"].should == "828ef3fdfa96f00ad9f27c383fc9ac7f"
|
45
|
-
finish
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'POST request' do
|
51
|
-
it 'can send a request body' do
|
52
|
-
client.post("/posted", {}, "some data") do |response|
|
53
|
-
response.status.should == 201
|
54
|
-
response["Created"].should == "awesome"
|
55
|
-
finish
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'PUT request' do
|
61
|
-
it 'can send a request body' do
|
62
|
-
client.put("/shelf/ctm", {}, "some data") do |response|
|
63
|
-
response.status.should == 200
|
64
|
-
response["Location"].should == "/shelf/ctm"
|
65
|
-
finish
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
share_examples_for "Synchronous Request API" do
|
4
|
-
context 'DELETE request' do
|
5
|
-
it 'can handle a No Content response' do
|
6
|
-
response = client.delete("/shelf/ctm")
|
7
|
-
response.status.should == 204
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'GET request' do
|
12
|
-
it 'has the proper response for a basic request' do
|
13
|
-
response = client.get("/ping")
|
14
|
-
response.status.should == 200
|
15
|
-
response.body.to_s.should == 'pong'
|
16
|
-
response["Content-Type"].should == 'text/html'
|
17
|
-
response["Content-Length"].to_i.should == 4
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'can handle a temporary redirect response' do
|
21
|
-
response = client.get("/redirect")
|
22
|
-
response.status.should == 302
|
23
|
-
response["Location"].should == "/after-redirect"
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'can return an empty body' do
|
27
|
-
response = client.get("/empty")
|
28
|
-
response.body.should be_empty
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'HEAD request' do
|
33
|
-
it 'can handle ETag headers' do
|
34
|
-
response = client.head("/shelf")
|
35
|
-
response.status.should == 200
|
36
|
-
response["ETag"].should == "828ef3fdfa96f00ad9f27c383fc9ac7f"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'POST request' do
|
41
|
-
it 'can send a request body' do
|
42
|
-
response = client.post("/posted", {}, "some data")
|
43
|
-
response.status.should == 201
|
44
|
-
response["Created"].should == "awesome"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'PUT request' do
|
49
|
-
it 'can send a request body' do
|
50
|
-
response = client.put("/shelf/ctm", {}, "some data")
|
51
|
-
response.status.should == 200
|
52
|
-
response["Location"].should == "/shelf/ctm"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/spec/middleware_helper.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
class LoggerCheck
|
2
|
-
def initialize(app, &block)
|
3
|
-
@app, @block = app, block
|
4
|
-
end
|
5
|
-
|
6
|
-
def call(env)
|
7
|
-
logger = env['rack.logger']
|
8
|
-
|
9
|
-
@app.call(env)
|
10
|
-
ensure
|
11
|
-
@block.call(logger)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class ETagFixed < Rack::ETag
|
16
|
-
def call(env)
|
17
|
-
status, headers, body = @app.call(env)
|
18
|
-
|
19
|
-
if !headers.has_key?('ETag')
|
20
|
-
digest, body = digest_body(body)
|
21
|
-
headers['ETag'] = %("#{digest}")
|
22
|
-
end
|
23
|
-
|
24
|
-
[status, headers, body]
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def digest_body(body)
|
29
|
-
digest = Digest::MD5.new
|
30
|
-
parts = []
|
31
|
-
body.each do |part|
|
32
|
-
digest << part
|
33
|
-
parts << part
|
34
|
-
end
|
35
|
-
[digest.hexdigest, parts]
|
36
|
-
end
|
37
|
-
end
|
data/spec/middleware_spec.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe Rack::Client, "with a standard piece of Rack middleware" do
|
4
|
-
context "Rack::ETag" do
|
5
|
-
let(:client) do
|
6
|
-
Rack::Client.new("http://localhost:#{server.port}") do
|
7
|
-
use Rack::ETag
|
8
|
-
run Rack::Client::Handler::NetHTTP
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "successfully uses that middleware" do
|
13
|
-
pending "Rack::ETag fixes streaming bodies (http://github.com/rack/rack/commit/f10713cce876d370ee5f1018928521d4b43e0dce)"
|
14
|
-
|
15
|
-
response = client.get("http://localhost:#{server.port}/no-etag")
|
16
|
-
response.status.should == 200
|
17
|
-
response.headers["ETag"].should_not be_empty
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "Rack::ETag (fixed for streaming)" do
|
22
|
-
let(:client) do
|
23
|
-
Rack::Client.new("http://localhost:#{server.port}") do
|
24
|
-
use ETagFixed
|
25
|
-
run Rack::Client::Handler::NetHTTP
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it "successfully uses that middleware" do
|
30
|
-
response = client.get("http://localhost:#{server.port}/no-etag")
|
31
|
-
response.status.should == 200
|
32
|
-
response.headers["ETag"].should_not be_empty
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "Rack::Logger" do
|
37
|
-
let(:client) do
|
38
|
-
Rack::Client.new("http://localhost:#{server.port}") do
|
39
|
-
use Rack::Logger
|
40
|
-
use LoggerCheck do |logger|
|
41
|
-
logger.class.should == Logger
|
42
|
-
end
|
43
|
-
run Rack::Client::Handler::NetHTTP
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it "successfully uses that middleware" do
|
48
|
-
response = client.get("http://localhost:#{server.port}/no-etag")
|
49
|
-
response.status.should == 200
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
data/spec/parser/json_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Rack::Client::Parser::JSON do
|
4
|
-
let(:client) do
|
5
|
-
Rack::Client.new("http://localhost:#{server.port}") do
|
6
|
-
use Rack::Client::Parser
|
7
|
-
run Rack::Client::Handler::NetHTTP
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'Synchronous API' do
|
12
|
-
it "injects the parsed body into the response" do
|
13
|
-
response = client.get("http://localhost:#{server.port}/hash.json")
|
14
|
-
response.headers['rack-client.body_collection'].should == [{'foo' => 'bar'}]
|
15
|
-
end
|
16
|
-
|
17
|
-
it "injects the dumped body into the request" do
|
18
|
-
response = client.post("http://localhost:#{server.port}/echo", {'rack-client.body_collection' => [{'foo' => 'bar'}], 'Content-Type' => 'application/json'}, {})
|
19
|
-
response.headers['rack-client.body_collection'].should == [{'foo' => 'bar'}]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/parser/yaml_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Rack::Client::Parser::YAML do
|
4
|
-
let(:client) do
|
5
|
-
Rack::Client.new("http://localhost:#{server.port}") do
|
6
|
-
use Rack::Client::Parser
|
7
|
-
run Rack::Client::Handler::NetHTTP
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'Synchronous API' do
|
12
|
-
it "injects the parsed body into the response" do
|
13
|
-
response = client.get("http://localhost:#{server.port}/hash.yml")
|
14
|
-
response.headers['rack-client.body_collection'].should == [{:foo => :bar}]
|
15
|
-
end
|
16
|
-
|
17
|
-
it "injects the dumped body into the request" do
|
18
|
-
response = client.post("http://localhost:#{server.port}/echo", {'rack-client.body_collection' => [{:foo => :bar}], 'Content-Type' => 'application/x-yaml'}, {})
|
19
|
-
response.headers['rack-client.body_collection'].should == [{:foo => :bar}]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/server_helper.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
class InThreadServer
|
2
|
-
def self.rackup(*a)
|
3
|
-
server = new(*a)
|
4
|
-
server.start
|
5
|
-
server
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :port, :port_range, :pre_spawn_callback, :config_ru, :running
|
9
|
-
|
10
|
-
def initialize(config_ru, pre_spawn_callback = nil, port_range = 8000..10000)
|
11
|
-
@config_ru, @pre_spawn_callback, @port_range = config_ru, pre_spawn_callback, port_range
|
12
|
-
end
|
13
|
-
|
14
|
-
def start
|
15
|
-
return if running
|
16
|
-
find_port
|
17
|
-
pre_spawn
|
18
|
-
spawn_server_thread
|
19
|
-
wait_for_server
|
20
|
-
@running = true
|
21
|
-
end
|
22
|
-
|
23
|
-
def stop
|
24
|
-
@thread.kill
|
25
|
-
@running= false
|
26
|
-
end
|
27
|
-
|
28
|
-
def find_port
|
29
|
-
return if @port
|
30
|
-
|
31
|
-
@port = @port_range.min
|
32
|
-
|
33
|
-
while(system("lsof -i tcp:#{self.port} > /dev/null")) do
|
34
|
-
@port += 1
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def pre_spawn
|
39
|
-
pre_spawn_callback.call(self) if pre_spawn_callback
|
40
|
-
end
|
41
|
-
|
42
|
-
def spawn_server_thread
|
43
|
-
@thread ||= Thread.new {
|
44
|
-
begin
|
45
|
-
Rack::Server.new(:Port => @port, :config => @config_ru, :server => 'mongrel').start
|
46
|
-
rescue
|
47
|
-
$stderr.puts "Failed to start server"
|
48
|
-
$stderr.puts $!.inspect
|
49
|
-
$stderr.puts $!.backtrace
|
50
|
-
abort
|
51
|
-
end
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
def wait_for_server
|
56
|
-
loop do
|
57
|
-
begin
|
58
|
-
Rack::Client.get("http://127.0.0.1:#{@port}/")
|
59
|
-
break
|
60
|
-
rescue Errno::ECONNREFUSED
|
61
|
-
sleep 1
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class DigestServer < Rack::Auth::Digest::MD5
|
68
|
-
def initialize(*)
|
69
|
-
super
|
70
|
-
self.opaque = '12345'
|
71
|
-
end
|
72
|
-
end
|