webmachine 1.6.0 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -5
- data/documentation/adapters.md +2 -11
- data/examples/debugger.rb +5 -3
- data/examples/logging.rb +2 -2
- data/examples/webrick.rb +2 -2
- data/lib/webmachine/adapter.rb +0 -3
- data/lib/webmachine/adapters/lazy_request_body.rb +1 -1
- data/lib/webmachine/adapters/rack.rb +38 -34
- data/lib/webmachine/adapters/rack_mapped.rb +1 -2
- data/lib/webmachine/adapters/webrick.rb +11 -12
- data/lib/webmachine/adapters.rb +0 -2
- data/lib/webmachine/application.rb +2 -2
- data/lib/webmachine/chunked_body.rb +1 -1
- data/lib/webmachine/configuration.rb +1 -1
- data/lib/webmachine/constants.rb +12 -12
- data/lib/webmachine/cookie.rb +20 -18
- data/lib/webmachine/decision/conneg.rb +24 -24
- data/lib/webmachine/decision/falsey.rb +0 -1
- data/lib/webmachine/decision/flow.rb +19 -20
- data/lib/webmachine/decision/fsm.rb +4 -4
- data/lib/webmachine/decision/helpers.rb +21 -21
- data/lib/webmachine/dispatcher/route.rb +28 -28
- data/lib/webmachine/dispatcher.rb +3 -2
- data/lib/webmachine/errors.rb +7 -8
- data/lib/webmachine/etags.rb +2 -1
- data/lib/webmachine/header_negotiation.rb +5 -6
- data/lib/webmachine/headers.rb +5 -5
- data/lib/webmachine/media_type.rb +5 -5
- data/lib/webmachine/quoted_string.rb +3 -3
- data/lib/webmachine/request.rb +7 -10
- data/lib/webmachine/rescueable_exception.rb +3 -3
- data/lib/webmachine/resource/authentication.rb +3 -4
- data/lib/webmachine/resource/callbacks.rb +3 -3
- data/lib/webmachine/resource/encodings.rb +3 -9
- data/lib/webmachine/resource.rb +1 -1
- data/lib/webmachine/response.rb +7 -9
- data/lib/webmachine/spec/adapter_lint.rb +67 -69
- data/lib/webmachine/spec/test_resource.rb +22 -22
- data/lib/webmachine/streaming/encoder.rb +3 -2
- data/lib/webmachine/streaming/io_encoder.rb +4 -3
- data/lib/webmachine/trace/fsm.rb +25 -18
- data/lib/webmachine/trace/resource_proxy.rb +10 -9
- data/lib/webmachine/trace/static/http-headers-status-v3.png +0 -0
- data/lib/webmachine/trace/trace_resource.rb +22 -24
- data/lib/webmachine/trace.rb +7 -6
- data/lib/webmachine/translation.rb +3 -3
- data/lib/webmachine/version.rb +1 -1
- metadata +52 -86
- data/.gitignore +0 -31
- data/Gemfile +0 -46
- data/Guardfile +0 -11
- data/RELEASING.md +0 -21
- data/Rakefile +0 -44
- data/lib/webmachine/adapters/httpkit.rb +0 -74
- data/lib/webmachine/adapters/reel.rb +0 -113
- data/memory_test.rb +0 -37
- data/spec/spec_helper.rb +0 -56
- data/spec/webmachine/adapter_spec.rb +0 -39
- data/spec/webmachine/adapters/httpkit_spec.rb +0 -10
- data/spec/webmachine/adapters/rack_mapped_spec.rb +0 -71
- data/spec/webmachine/adapters/rack_spec.rb +0 -62
- data/spec/webmachine/adapters/reel_spec.rb +0 -76
- data/spec/webmachine/adapters/webrick_spec.rb +0 -12
- data/spec/webmachine/application_spec.rb +0 -74
- data/spec/webmachine/chunked_body_spec.rb +0 -30
- data/spec/webmachine/configuration_spec.rb +0 -27
- data/spec/webmachine/cookie_spec.rb +0 -99
- data/spec/webmachine/decision/conneg_spec.rb +0 -166
- data/spec/webmachine/decision/falsey_spec.rb +0 -8
- data/spec/webmachine/decision/flow_spec.rb +0 -1148
- data/spec/webmachine/decision/fsm_spec.rb +0 -163
- data/spec/webmachine/decision/helpers_spec.rb +0 -216
- data/spec/webmachine/dispatcher/rfc3986_percent_decode_spec.rb +0 -22
- data/spec/webmachine/dispatcher/route_spec.rb +0 -248
- data/spec/webmachine/dispatcher_spec.rb +0 -104
- data/spec/webmachine/errors_spec.rb +0 -13
- data/spec/webmachine/etags_spec.rb +0 -75
- data/spec/webmachine/events_spec.rb +0 -58
- data/spec/webmachine/headers_spec.rb +0 -99
- data/spec/webmachine/media_type_spec.rb +0 -85
- data/spec/webmachine/request_spec.rb +0 -273
- data/spec/webmachine/rescueable_exception_spec.rb +0 -15
- data/spec/webmachine/resource/authentication_spec.rb +0 -68
- data/spec/webmachine/response_spec.rb +0 -51
- data/spec/webmachine/trace/fsm_spec.rb +0 -37
- data/spec/webmachine/trace/resource_proxy_spec.rb +0 -34
- data/spec/webmachine/trace/trace_store_spec.rb +0 -29
- data/spec/webmachine/trace_spec.rb +0 -17
- data/webmachine.gemspec +0 -25
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Webmachine::Cookie do
|
4
|
-
describe "creating a cookie" do
|
5
|
-
let(:name) { "monster" }
|
6
|
-
let(:value) { "mash" }
|
7
|
-
let(:attributes) { {} }
|
8
|
-
|
9
|
-
let(:cookie) { Webmachine::Cookie.new(name, value, attributes) }
|
10
|
-
|
11
|
-
subject { cookie }
|
12
|
-
|
13
|
-
its(:name) { should == name }
|
14
|
-
its(:value) { should == value }
|
15
|
-
|
16
|
-
its(:to_s) { should == "monster=mash" }
|
17
|
-
|
18
|
-
describe "a cookie with whitespace in name and value" do
|
19
|
-
let(:name) { "cookie name" }
|
20
|
-
let(:value) { "cookie value" }
|
21
|
-
|
22
|
-
its(:to_s) { should == "cookie+name=cookie+value" }
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "a cookie with attributes set" do
|
26
|
-
let(:domain) { "www.server.com" }
|
27
|
-
let(:path) { "/" }
|
28
|
-
let(:comment) { "comment with spaces" }
|
29
|
-
let(:version) { 1 }
|
30
|
-
let(:maxage) { 60 }
|
31
|
-
let(:expires) { Time.gm(2010,3,14, 3, 14, 0) }
|
32
|
-
let(:attributes) {
|
33
|
-
{
|
34
|
-
:comment => comment,
|
35
|
-
:domain => domain,
|
36
|
-
:path => path,
|
37
|
-
:secure => true,
|
38
|
-
:httponly => true,
|
39
|
-
:version => version,
|
40
|
-
:maxage => maxage,
|
41
|
-
:expires => expires
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
its(:secure?) { should be true }
|
46
|
-
its(:http_only?) { should be true }
|
47
|
-
its(:comment) { should == comment }
|
48
|
-
its(:domain) { should == domain }
|
49
|
-
its(:path) { should == path }
|
50
|
-
its(:version) { should == version }
|
51
|
-
its(:maxage) { should == maxage }
|
52
|
-
its(:expires) { should == expires }
|
53
|
-
|
54
|
-
it "should include the attributes in its string version" do
|
55
|
-
str = subject.to_s
|
56
|
-
expect(str).to include "Secure"
|
57
|
-
expect(str).to include "HttpOnly"
|
58
|
-
expect(str).to include "Comment=comment+with+spaces"
|
59
|
-
expect(str).to include "Domain=www.server.com"
|
60
|
-
expect(str).to include "Path=/"
|
61
|
-
expect(str).to include "Version=1"
|
62
|
-
expect(str).to include "Max-Age=60"
|
63
|
-
expect(str).to include "Expires=Sun, 14-Mar-2010 03:14:00 GMT"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "parsing a cookie parameter" do
|
69
|
-
let(:str) { "cookie = monster" }
|
70
|
-
|
71
|
-
subject { Webmachine::Cookie.parse(str) }
|
72
|
-
|
73
|
-
it("should have the cookie") { expect(subject).to eq({ "cookie" => "monster" }) }
|
74
|
-
|
75
|
-
describe "parsing multiple cookie parameters" do
|
76
|
-
let(:str) { "cookie=monster; monster=mash" }
|
77
|
-
|
78
|
-
it("should have both cookies") { expect(subject).to eq({ "cookie" => "monster", "monster" => "mash" }) }
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "parsing an encoded cookie" do
|
82
|
-
let(:str) { "cookie=yum+yum" }
|
83
|
-
|
84
|
-
it("should decode the cookie") { expect(subject).to eq({ "cookie" => "yum yum" }) }
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "parsing nil" do
|
88
|
-
let(:str) { nil }
|
89
|
-
|
90
|
-
it("should return empty hash") { expect(subject).to eq({}) }
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "parsing duplicate cookies" do
|
94
|
-
let(:str) { "cookie=monster; cookie=yum+yum" }
|
95
|
-
|
96
|
-
it("should return the first instance of the cookie") { expect(subject).to eq({ "cookie" => "monster" }) }
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,166 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Webmachine::Decision::Conneg do
|
4
|
-
include_context "default resource"
|
5
|
-
|
6
|
-
subject do
|
7
|
-
Webmachine::Decision::FSM.new(resource, request, response)
|
8
|
-
end
|
9
|
-
|
10
|
-
context "choosing a media type" do
|
11
|
-
it "should not choose a type when none are provided" do
|
12
|
-
expect(subject.choose_media_type([], "*/*")).to be_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should not choose a type when none are acceptable" do
|
16
|
-
expect(subject.choose_media_type(["text/html"], "application/json")).to be_nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should choose the first acceptable type" do
|
20
|
-
expect(subject.choose_media_type(["text/html", "application/xml"],
|
21
|
-
"application/xml, text/html, */*")).to eq("application/xml")
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should choose the type that matches closest when matching subparams" do
|
25
|
-
expect(subject.choose_media_type(["text/html",
|
26
|
-
["text/html", {"charset" => "iso8859-1"}]],
|
27
|
-
"text/html;charset=iso8859-1, application/xml")).
|
28
|
-
to eq("text/html;charset=iso8859-1")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should choose a type more specific than requested when an exact match is not present" do
|
32
|
-
expect(subject.choose_media_type(["application/json;v=3;foo=bar", "application/json;v=2"],
|
33
|
-
"text/html, application/json")).
|
34
|
-
to eq("application/json;v=3;foo=bar")
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
it "should choose the preferred type over less-preferred types" do
|
39
|
-
expect(subject.choose_media_type(["text/html", "application/xml"],
|
40
|
-
"application/xml;q=0.7, text/html, */*")).to eq("text/html")
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should raise an error when a media-type is improperly formatted" do
|
45
|
-
expect {
|
46
|
-
subject.choose_media_type(["text/html", "application/xml"],
|
47
|
-
"bah;")
|
48
|
-
}.to raise_error(Webmachine::MalformedRequest)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should choose a type when more than one accept header is present" do
|
52
|
-
expect(subject.choose_media_type(["text/html"],
|
53
|
-
["text/html", "text/plain"])).to eq("text/html")
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "choosing an encoding" do
|
59
|
-
it "should not set the encoding when none are provided" do
|
60
|
-
subject.choose_encoding({}, "identity, gzip")
|
61
|
-
expect(subject.metadata['Content-Encoding']).to be_nil
|
62
|
-
expect(subject.response.headers['Content-Encoding']).to be_nil
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should not set the Content-Encoding header when it is identity" do
|
66
|
-
subject.choose_encoding({"gzip"=> :encode_gzip, "identity" => :encode_identity}, "identity")
|
67
|
-
expect(subject.metadata['Content-Encoding']).to eq('identity')
|
68
|
-
expect(response.headers['Content-Encoding']).to be_nil
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should choose the first acceptable encoding" do
|
72
|
-
subject.choose_encoding({"gzip" => :encode_gzip}, "identity, gzip")
|
73
|
-
expect(subject.metadata['Content-Encoding']).to eq('gzip')
|
74
|
-
expect(response.headers['Content-Encoding']).to eq('gzip')
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should choose the first acceptable encoding" \
|
78
|
-
", even when no white space after comma" do
|
79
|
-
subject.choose_encoding({"gzip" => :encode_gzip}, "identity,gzip")
|
80
|
-
expect(subject.metadata['Content-Encoding']).to eq('gzip')
|
81
|
-
expect(response.headers['Content-Encoding']).to eq('gzip')
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should choose the preferred encoding over less-preferred encodings" do
|
85
|
-
subject.choose_encoding({"gzip" => :encode_gzip, "identity" => :encode_identity}, "gzip, identity;q=0.7")
|
86
|
-
expect(subject.metadata['Content-Encoding']).to eq('gzip')
|
87
|
-
expect(response.headers['Content-Encoding']).to eq('gzip')
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should not set the encoding if none are acceptable" do
|
91
|
-
subject.choose_encoding({"gzip" => :encode_gzip}, "identity")
|
92
|
-
expect(subject.metadata['Content-Encoding']).to be_nil
|
93
|
-
expect(response.headers['Content-Encoding']).to be_nil
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "choosing a charset" do
|
98
|
-
it "should not set the charset when none are provided" do
|
99
|
-
subject.choose_charset([], "ISO-8859-1")
|
100
|
-
expect(subject.metadata['Charset']).to be_nil
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should choose the first acceptable charset" do
|
104
|
-
subject.choose_charset([["UTF-8", :to_utf8],["US-ASCII", :to_ascii]], "US-ASCII, UTF-8")
|
105
|
-
expect(subject.metadata['Charset']).to eq("US-ASCII")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should choose the preferred charset over less-preferred charsets" do
|
109
|
-
subject.choose_charset([["UTF-8", :to_utf8],["US-ASCII", :to_ascii]], "US-ASCII;q=0.7, UTF-8")
|
110
|
-
expect(subject.metadata['Charset']).to eq("UTF-8")
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should not set the charset if none are acceptable" do
|
114
|
-
subject.choose_charset([["UTF-8", :to_utf8],["US-ASCII", :to_ascii]], "ISO-8859-1")
|
115
|
-
expect(subject.metadata['Charset']).to be_nil
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should choose a charset case-insensitively" do
|
119
|
-
subject.choose_charset([["UtF-8", :to_utf8],["US-ASCII", :to_ascii]], "iso-8859-1, utf-8")
|
120
|
-
expect(subject.metadata['Charset']).to eq("utf-8")
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context "choosing a language" do
|
125
|
-
it "should not set the language when none are provided" do
|
126
|
-
subject.choose_language([], "en")
|
127
|
-
expect(subject.metadata['Language']).to be_nil
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should choose the first acceptable language" do
|
131
|
-
subject.choose_language(['en', 'en-US', 'es'], "en-US, es")
|
132
|
-
expect(subject.metadata['Language']).to eq("en-US")
|
133
|
-
expect(response.headers['Content-Language']).to eq("en-US")
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should choose the preferred language over less-preferred languages" do
|
137
|
-
subject.choose_language(['en', 'en-US', 'es'], "en-US;q=0.6, es")
|
138
|
-
expect(subject.metadata['Language']).to eq("es")
|
139
|
-
expect(response.headers['Content-Language']).to eq("es")
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should select the first language if all are acceptable" do
|
143
|
-
subject.choose_language(['en', 'fr', 'es'], "*")
|
144
|
-
expect(subject.metadata['Language']).to eq("en")
|
145
|
-
expect(response.headers['Content-Language']).to eq("en")
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should select the closest acceptable language when an exact match is not available" do
|
149
|
-
subject.choose_language(['en-US', 'es'], "en, fr")
|
150
|
-
expect(subject.metadata['Language']).to eq('en-US')
|
151
|
-
expect(response.headers['Content-Language']).to eq('en-US')
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should not set the language if none are acceptable" do
|
155
|
-
subject.choose_language(['en'], 'es')
|
156
|
-
expect(subject.metadata['Language']).to be_nil
|
157
|
-
expect(response.headers).not_to include('Content-Language')
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should choose a language case-insensitively" do
|
161
|
-
subject.choose_language(['en-US', 'ZH'], 'zh-ch, EN')
|
162
|
-
expect(subject.metadata['Language']).to eq('en-US')
|
163
|
-
expect(response.headers['Content-Language']).to eq('en-US')
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Webmachine::Decision::Falsey do
|
4
|
-
specify { expect(described_class.=== false).to be(true) }
|
5
|
-
specify { expect(described_class.=== nil).to be(true) }
|
6
|
-
specify { expect(described_class.=== true).to be(false) }
|
7
|
-
specify { expect(described_class.=== []).to be(false) }
|
8
|
-
end
|