http_objects 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +56 -0
- data/Rakefile +12 -0
- data/http_objects.gemspec +20 -0
- data/lib/http_objects/hash.rb +51 -0
- data/lib/http_objects/headers/attributes.rb +38 -0
- data/lib/http_objects/headers/directives/cache.rb +80 -0
- data/lib/http_objects/headers/entity.rb +43 -0
- data/lib/http_objects/headers/general.rb +42 -0
- data/lib/http_objects/headers/request.rb +116 -0
- data/lib/http_objects/headers/response.rb +55 -0
- data/lib/http_objects/headers/tools.rb +29 -0
- data/lib/http_objects/headers.rb +27 -0
- data/lib/http_objects/headers_hash.rb +25 -0
- data/lib/http_objects/parameters/basic_rules.rb +62 -0
- data/lib/http_objects/parameters/date_time.rb +19 -0
- data/lib/http_objects/parameters/entity_tags.rb +27 -0
- data/lib/http_objects/parameters/language_tags.rb +16 -0
- data/lib/http_objects/parameters/media_type.rb +29 -0
- data/lib/http_objects/parameters/uri.rb +21 -0
- data/lib/http_objects/parameters.rb +15 -0
- data/lib/http_objects/version.rb +3 -0
- data/lib/http_objects.rb +5 -0
- data/test/http_objects/hash_test.rb +74 -0
- data/test/http_objects/headers/attributes_test.rb +26 -0
- data/test/http_objects/headers/directives/cache_test.rb +72 -0
- data/test/http_objects/headers/entity/allow_test.rb +13 -0
- data/test/http_objects/headers/entity/content_encoding_test.rb +13 -0
- data/test/http_objects/headers/entity/content_language_test.rb +13 -0
- data/test/http_objects/headers/entity/content_lenght_test.rb +13 -0
- data/test/http_objects/headers/entity/content_location_test.rb +13 -0
- data/test/http_objects/headers/entity/content_md5_test.rb +13 -0
- data/test/http_objects/headers/entity/content_type_test.rb +12 -0
- data/test/http_objects/headers/entity/expires_test.rb +12 -0
- data/test/http_objects/headers/entity/last_modified_test.rb +12 -0
- data/test/http_objects/headers/general_test.rb +59 -0
- data/test/http_objects/headers/request/host_test.rb +13 -0
- data/test/http_objects/headers/request/if_match_test.rb +21 -0
- data/test/http_objects/headers/request/if_modified_since_test.rb +13 -0
- data/test/http_objects/headers/request/if_none_match_test.rb +21 -0
- data/test/http_objects/headers/request/if_range_test.rb +21 -0
- data/test/http_objects/headers/request/if_unmodified_since_test.rb +13 -0
- data/test/http_objects/headers/request/max_forwards_test.rb +13 -0
- data/test/http_objects/headers/request/referer_test.rb +13 -0
- data/test/http_objects/headers/response/age_test.rb +13 -0
- data/test/http_objects/headers/response/etag_test.rb +13 -0
- data/test/http_objects/headers/response/location_test.rb +13 -0
- data/test/http_objects/headers/response/retry_after_test.rb +21 -0
- data/test/http_objects/headers/tools_test.rb +28 -0
- data/test/http_objects/headers_hash_test.rb +18 -0
- data/test/http_objects/http_objects_test.rb +4 -0
- data/test/http_objects/parameters/basic_rules_test.rb +73 -0
- data/test/http_objects/parameters/date_time_test.rb +43 -0
- data/test/http_objects/parameters/entity_tags_test.rb +43 -0
- data/test/http_objects/parameters/language_tags_test.rb +36 -0
- data/test/http_objects/parameters/media_type_test.rb +22 -0
- data/test/http_objects/parameters/uri_test.rb +36 -0
- data/test/test_helper.rb +7 -0
- metadata +202 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
module HttpObjects::Parameters
|
2
|
+
|
3
|
+
# 2.2 Basic Rules
|
4
|
+
# This module implement some basic parsing constructs, from RFC 2616.
|
5
|
+
module BasicRules
|
6
|
+
|
7
|
+
# Public: Base interface for HTTP Header.
|
8
|
+
# HTTP Header should have:
|
9
|
+
#
|
10
|
+
# # parse method that returns self instance.
|
11
|
+
# Base.parse("value") # => <# Base instance >
|
12
|
+
#
|
13
|
+
# # constructor with raw and value.
|
14
|
+
# header = Base.new("raw", "value")
|
15
|
+
class Base
|
16
|
+
attr_reader :raw, :value
|
17
|
+
|
18
|
+
def self.parse(value)
|
19
|
+
raise "Not implemented. You should override this method and return an instance of yourself. See HttpObjects::Parameters::BasicRules source for examples."
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(raw, value)
|
23
|
+
@raw, @value = raw, value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Public: Mapped to String.
|
28
|
+
# token = 1*<any CHAR except CTLs or separators>
|
29
|
+
class Token < Base
|
30
|
+
def self.parse(value)
|
31
|
+
self.new(value, value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Public: Mapped to Integer.
|
36
|
+
# DIGIT = <any US-ASCII digit "0".."9">
|
37
|
+
class Digit < Base
|
38
|
+
def self.parse(value)
|
39
|
+
self.new(value, value.to_i)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Public: Mapped to String#upcase.
|
44
|
+
# UPALPHA = <any US-ASCII uppercase letter "A".."Z">
|
45
|
+
class UpAlpha < Base
|
46
|
+
def self.parse(value)
|
47
|
+
self.new(value, value.to_s.upcase)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Public: Mapped to String#downcase.
|
52
|
+
# LOALPHA = <any US-ASCII lowercase letter "a".."z">
|
53
|
+
class LoAlpha < Base
|
54
|
+
def self.parse(value)
|
55
|
+
self.new(value, value.to_s.downcase)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "time"
|
2
|
+
|
3
|
+
module HttpObjects::Parameters
|
4
|
+
|
5
|
+
# 3.3. Date/Time Formats
|
6
|
+
# Examples
|
7
|
+
# Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
|
8
|
+
# Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
|
9
|
+
class DateTime < HttpObjects::Parameters::BasicRules::Base
|
10
|
+
|
11
|
+
def self.parse(value)
|
12
|
+
raw = value
|
13
|
+
value = Time.parse(value, true) rescue nil
|
14
|
+
self.new(raw, value)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module HttpObjects::Parameters
|
2
|
+
|
3
|
+
# 3.11 Entity Tags
|
4
|
+
#
|
5
|
+
# Examples
|
6
|
+
# "123456789" -- A strong ETag validator
|
7
|
+
# W/"123456789" -- A weak ETag validator
|
8
|
+
class EntityTags < HttpObjects::Parameters::BasicRules::Base
|
9
|
+
|
10
|
+
def self.parse(value)
|
11
|
+
raw = value
|
12
|
+
if (match = value.match(/("\w*")/))
|
13
|
+
value = match[1]
|
14
|
+
else
|
15
|
+
value = ""
|
16
|
+
end
|
17
|
+
self.new(raw, value.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns true if raw start with 'W/'
|
21
|
+
def weak?
|
22
|
+
@raw.start_with?("W/")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module HttpObjects::Parameters
|
2
|
+
|
3
|
+
# 3.10 Language Tags
|
4
|
+
# Examples
|
5
|
+
# en, en-US, en-cockney, i-cherokee, x-pig-latin
|
6
|
+
class LanguageTags < HttpObjects::Parameters::BasicRules::Base
|
7
|
+
|
8
|
+
def self.parse(value)
|
9
|
+
raw = value
|
10
|
+
value = value.to_s.gsub(/(\s+)/, "").split(",")
|
11
|
+
self.new(raw, value)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module HttpObjects::Parameters
|
2
|
+
|
3
|
+
# 3.7. Media Types
|
4
|
+
# Examples
|
5
|
+
# text/html; charset=ISO-8859-4
|
6
|
+
class MediaType
|
7
|
+
|
8
|
+
attr_reader :raw, :value, :parameters
|
9
|
+
|
10
|
+
def self.parse(value)
|
11
|
+
raw = value
|
12
|
+
value, params = value.split(";", 2)
|
13
|
+
|
14
|
+
parameters = {}
|
15
|
+
params.split(/\s*;\s*/).each do |param|
|
16
|
+
name, param_value = param.split(/=/)
|
17
|
+
name = name.gsub(/\s*/, "")
|
18
|
+
parameters[name.downcase] = param_value
|
19
|
+
end
|
20
|
+
self.new(raw, value, parameters)
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(raw, value, parameters)
|
24
|
+
@raw, @value, @parameters = raw, value, parameters
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
module HttpObjects::Parameters
|
4
|
+
|
5
|
+
# 3.2 Uniform Resource Identifiers
|
6
|
+
# Examples
|
7
|
+
# http://abc.com:80/~smith/home.html
|
8
|
+
# /~smith/home.html
|
9
|
+
class Uri < HttpObjects::Parameters::BasicRules::Base
|
10
|
+
|
11
|
+
def self.parse(value)
|
12
|
+
raw = value
|
13
|
+
if !(value.nil? || value == "")
|
14
|
+
value = URI.parse(value.to_s)
|
15
|
+
end
|
16
|
+
self.new(raw, value)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "http_objects/parameters/basic_rules"
|
2
|
+
require "http_objects/parameters/uri"
|
3
|
+
require "http_objects/parameters/date_time"
|
4
|
+
require "http_objects/parameters/media_type"
|
5
|
+
require "http_objects/parameters/language_tags"
|
6
|
+
require "http_objects/parameters/entity_tags"
|
7
|
+
|
8
|
+
module HttpObjects
|
9
|
+
|
10
|
+
# 3 Protocol Parameters
|
11
|
+
# This module have implementatios for Protocol Parameters from RFC 2616.
|
12
|
+
module Parameters
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/http_objects.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe HttpObjects::Hash do
|
4
|
+
|
5
|
+
MyObject = Class.new do
|
6
|
+
attr_reader :value, :raw
|
7
|
+
def self.header_name
|
8
|
+
"MyObject"
|
9
|
+
end
|
10
|
+
def self.parse(value)
|
11
|
+
self.new(value)
|
12
|
+
end
|
13
|
+
def initialize(value)
|
14
|
+
@raw, @value = value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class TestHash < HttpObjects::Hash
|
19
|
+
add_attribute(MyObject)
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { TestHash.new }
|
23
|
+
|
24
|
+
describe "#initialize" do
|
25
|
+
subject { TestHash }
|
26
|
+
it "without value" do
|
27
|
+
subject.new.must_be_kind_of(HttpObjects::Hash)
|
28
|
+
end
|
29
|
+
it "with values" do
|
30
|
+
hash = subject.new("MyObject" => "value")
|
31
|
+
hash["MyObject"].must_be_instance_of(MyObject)
|
32
|
+
end
|
33
|
+
it "should reuse same object" do
|
34
|
+
hash_headers = subject.new("MyObject" => "value")
|
35
|
+
hash = subject.new(hash_headers)
|
36
|
+
hash.must_be_same_as(hash_headers)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#[]=" do
|
41
|
+
it "simple value" do
|
42
|
+
subject["chave"] = "valor"
|
43
|
+
subject["chave"].must_equal("valor")
|
44
|
+
end
|
45
|
+
it "HTTP Header value" do
|
46
|
+
subject["MyObject"] = "value"
|
47
|
+
subject["MyObject"].must_be_instance_of(MyObject)
|
48
|
+
end
|
49
|
+
it "without value" do
|
50
|
+
subject["MyObject"].must_be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#store as alias of []=" do
|
55
|
+
it "simple value" do
|
56
|
+
subject.store("chave", "valor")
|
57
|
+
subject["chave"].must_equal("valor")
|
58
|
+
end
|
59
|
+
it "HTTP Header value" do
|
60
|
+
subject.store("MyObject", "value")
|
61
|
+
subject["MyObject"].must_be_instance_of(MyObject)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "header as instance method" do
|
66
|
+
subject.store("MyObject", "value")
|
67
|
+
subject["MyObject"].must_be_instance_of(MyObject)
|
68
|
+
|
69
|
+
subject.myobject.must_be_instance_of(MyObject)
|
70
|
+
subject.myobject?.must_equal(true)
|
71
|
+
subject.myobject!.must_equal("value")
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestSubject
|
4
|
+
extend HttpObjects::Headers::Attributes
|
5
|
+
end
|
6
|
+
|
7
|
+
describe HttpObjects::Headers::Attributes do
|
8
|
+
|
9
|
+
MyAttribute = Class.new
|
10
|
+
|
11
|
+
it "#register_attribute - register header on .attributes" do
|
12
|
+
TestSubject.register_attribute("MyAttribute", MyAttribute)
|
13
|
+
TestSubject.attributes.must_equal({"MyAttribute" => MyAttribute})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "#register_attribute - should yield block if given" do
|
17
|
+
flag = "out block"
|
18
|
+
TestSubject.register_attribute("MyAttribute", MyAttribute) do |name, h|
|
19
|
+
name.must_equal("MyAttribute")
|
20
|
+
h.must_be_same_as(MyAttribute)
|
21
|
+
flag = "inner block"
|
22
|
+
end
|
23
|
+
flag.must_equal("inner block")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Directives
|
4
|
+
|
5
|
+
describe Cache do
|
6
|
+
|
7
|
+
describe "should accept empty declarations" do
|
8
|
+
subject { Cache.parse("") }
|
9
|
+
it "#raw" do
|
10
|
+
subject.raw.must_be_empty
|
11
|
+
end
|
12
|
+
it "#value" do
|
13
|
+
subject.value.must_be_empty
|
14
|
+
end
|
15
|
+
it "directives be false or zero" do
|
16
|
+
subject.no_cache?.must_equal(false)
|
17
|
+
subject.no_store?.must_equal(false)
|
18
|
+
subject.max_age?.must_equal(false)
|
19
|
+
subject.max_stale?.must_equal(false)
|
20
|
+
subject.min_fresh?.must_equal(false)
|
21
|
+
subject.no_transform?.must_equal(false)
|
22
|
+
subject.only_if_cached?.must_equal(false)
|
23
|
+
subject.public?.must_equal(false)
|
24
|
+
subject.private?.must_equal(false)
|
25
|
+
subject.must_revalidate?.must_equal(false)
|
26
|
+
subject.proxy_revalidate?.must_equal(false)
|
27
|
+
subject.s_maxage?.must_equal(false)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "should accept one-directive declaration" do
|
32
|
+
subject { Cache.parse("no-cache") }
|
33
|
+
it "#no_cache? be true" do
|
34
|
+
subject.no_cache?.must_equal(true)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "should accept standalone directives" do
|
39
|
+
subject { Cache.parse("no-cache, public") }
|
40
|
+
|
41
|
+
it "#public?" do
|
42
|
+
subject.public?.must_equal(true)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "should accept multi-directive declaration" do
|
47
|
+
subject { Cache.parse("no-cache, max-age=600, private = \"Accept\"") }
|
48
|
+
|
49
|
+
it "#no_cache? be true" do
|
50
|
+
subject.no_cache?.must_equal(true)
|
51
|
+
end
|
52
|
+
it "#max_age be 600" do
|
53
|
+
subject.max_age?.must_equal(true)
|
54
|
+
subject.max_age.value.must_equal(600)
|
55
|
+
end
|
56
|
+
it "#private be Accept" do
|
57
|
+
subject.private!.must_equal("Accept")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "should accept extension directives" do
|
62
|
+
subject { Cache.parse("private, community=\"UCI\", stand-alone-extension") }
|
63
|
+
|
64
|
+
it "should access extension directive with value" do
|
65
|
+
subject["community"].must_equal("UCI")
|
66
|
+
end
|
67
|
+
it "should access extension directive without value" do
|
68
|
+
subject.key?("stand-alone-extension").must_equal(true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Entity
|
4
|
+
|
5
|
+
describe Allow do
|
6
|
+
|
7
|
+
subject { Allow.parse("GET, HEAD, PUT") }
|
8
|
+
|
9
|
+
it "should be BasicRules::UpAlpha object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::UpAlpha)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Entity
|
4
|
+
|
5
|
+
describe ContentEncoding do
|
6
|
+
|
7
|
+
subject { ContentEncoding.parse("Gzip") }
|
8
|
+
|
9
|
+
it "should be BasicRules::LoAlpha object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::LoAlpha)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Entity
|
4
|
+
|
5
|
+
describe ContentLanguage do
|
6
|
+
|
7
|
+
subject { ContentLanguage.parse("text/html; charset=ISO-8859-4") }
|
8
|
+
|
9
|
+
it "should be Language Tags object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::LanguageTags)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Entity
|
4
|
+
|
5
|
+
describe ContentLength do
|
6
|
+
|
7
|
+
subject { ContentLength.parse("3495") }
|
8
|
+
|
9
|
+
it "should be BasicRules::Digit object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Digit)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Entity
|
4
|
+
|
5
|
+
describe ContentLocation do
|
6
|
+
|
7
|
+
subject { ContentLocation.parse("/relative_path") }
|
8
|
+
|
9
|
+
it "should be Uri object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::Uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Entity
|
4
|
+
|
5
|
+
describe ContentMD5 do
|
6
|
+
|
7
|
+
subject { ContentMD5.parse("aad883420fe64e865ba1725e5617222c") }
|
8
|
+
|
9
|
+
it "should be Token object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe HttpObjects::Headers::Entity::ContentType do
|
4
|
+
|
5
|
+
let(:subject_class) { HttpObjects::Headers::Entity::ContentType }
|
6
|
+
subject { subject_class.parse("text/html; charset=ISO-8859-4") }
|
7
|
+
|
8
|
+
it "should be Media Type object" do
|
9
|
+
subject.must_be_kind_of(HttpObjects::Parameters::MediaType)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe HttpObjects::Headers::Entity::Expires do
|
4
|
+
|
5
|
+
let(:subject_class) { HttpObjects::Headers::Entity::Expires }
|
6
|
+
subject { subject_class.parse("Sun, 06 Nov 1994 08:49:37 GMT") }
|
7
|
+
|
8
|
+
it "should be Date Time object" do
|
9
|
+
subject.must_be_kind_of(HttpObjects::Parameters::DateTime)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe HttpObjects::Headers::Entity::LastModified do
|
4
|
+
|
5
|
+
let(:subject_class) { HttpObjects::Headers::Entity::LastModified }
|
6
|
+
subject { subject_class.parse("Sun, 06 Nov 1994 08:49:37 GMT") }
|
7
|
+
|
8
|
+
it "should be Date Time object" do
|
9
|
+
subject.must_be_kind_of(HttpObjects::Parameters::DateTime)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::General
|
4
|
+
|
5
|
+
describe CacheControl do
|
6
|
+
subject { CacheControl.parse("no-cache, public") }
|
7
|
+
it "should be Cache directive object" do
|
8
|
+
subject.must_be_kind_of(HttpObjects::Headers::Directives::Cache)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Connection do
|
13
|
+
subject { Connection.parse("close") }
|
14
|
+
it "should be Token object" do
|
15
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe HttpObjects::Headers::General::Date do
|
20
|
+
subject { HttpObjects::Headers::General::Date.parse("Tue, 15 Nov 1994 08:12:31 GMT") }
|
21
|
+
it "should be DateTime object" do
|
22
|
+
subject.must_be_kind_of(HttpObjects::Parameters::DateTime)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Pragma do
|
27
|
+
subject { Pragma.parse("") }
|
28
|
+
it "should be Token object" do
|
29
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe Trailer do
|
34
|
+
subject { Trailer.parse("") }
|
35
|
+
it "should be Token object" do
|
36
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Upgrade do
|
41
|
+
subject { Upgrade.parse("HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11") }
|
42
|
+
it "should be Token object" do
|
43
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe Via do
|
48
|
+
subject { Via.parse("1.0 fred, 1.1 nowhere.com (Apache/1.1)") }
|
49
|
+
it "should be Token object" do
|
50
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe Warning do
|
55
|
+
subject { Warning.parse("") }
|
56
|
+
it "should be Token object" do
|
57
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Request
|
4
|
+
|
5
|
+
describe IfMatch do
|
6
|
+
|
7
|
+
describe "*" do
|
8
|
+
subject { IfMatch.parse("*") }
|
9
|
+
it "should be Token object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '"xyzzy"' do
|
15
|
+
subject { IfMatch.parse('"xyzzy"') }
|
16
|
+
it "should be EntityTags object" do
|
17
|
+
subject.must_be_kind_of(HttpObjects::Parameters::EntityTags)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Request
|
4
|
+
|
5
|
+
describe IfModifiedSince do
|
6
|
+
|
7
|
+
subject { IfModifiedSince.parse("Sat, 29 Oct 1994 19:43:31 GMT") }
|
8
|
+
|
9
|
+
it "should be Date Time object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::DateTime)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Request
|
4
|
+
|
5
|
+
describe IfNoneMatch do
|
6
|
+
|
7
|
+
describe "*" do
|
8
|
+
subject { IfNoneMatch.parse("*") }
|
9
|
+
it "should be Token object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::BasicRules::Token)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '"xyzzy"' do
|
15
|
+
subject { IfNoneMatch.parse('"xyzzy"') }
|
16
|
+
it "should be EntityTags object" do
|
17
|
+
subject.must_be_kind_of(HttpObjects::Parameters::EntityTags)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Request
|
4
|
+
|
5
|
+
describe IfRange do
|
6
|
+
|
7
|
+
describe "entity-tag" do
|
8
|
+
subject { IfRange.parse('W/"xyzzy"') }
|
9
|
+
it "should be EntityTags object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::EntityTags)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "HTTP-date" do
|
15
|
+
subject { IfRange.parse("Sat, 29 Oct 1994 19:43:31 GMT") }
|
16
|
+
it "should be Date Time object" do
|
17
|
+
subject.must_be_kind_of(HttpObjects::Parameters::DateTime)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
include HttpObjects::Headers::Request
|
4
|
+
|
5
|
+
describe IfUnmodifiedSince do
|
6
|
+
|
7
|
+
subject { IfUnmodifiedSince.parse("Sat, 29 Oct 1994 19:43:31 GMT") }
|
8
|
+
|
9
|
+
it "should be Date Time object" do
|
10
|
+
subject.must_be_kind_of(HttpObjects::Parameters::DateTime)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|