xenon-routing 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{xenon-routing/lib → lib}/xenon/api.rb +20 -11
- data/{xenon-routing/lib → lib}/xenon/marshallers.rb +24 -14
- data/{xenon-routing/lib → lib}/xenon/request.rb +10 -2
- data/{xenon-routing/lib → lib}/xenon/response.rb +0 -0
- data/{xenon-routing/lib → lib}/xenon/routing.rb +0 -0
- data/{xenon-routing/lib → lib}/xenon/routing/context.rb +0 -0
- data/{xenon-routing/lib → lib}/xenon/routing/directives.rb +1 -0
- data/{xenon-routing/lib → lib}/xenon/routing/header_directives.rb +0 -0
- data/lib/xenon/routing/marshalling_directives.rb +24 -0
- data/{xenon-routing/lib → lib}/xenon/routing/method_directives.rb +10 -4
- data/{xenon-routing/lib → lib}/xenon/routing/param_directives.rb +0 -0
- data/{xenon-routing/lib → lib}/xenon/routing/path_directives.rb +0 -0
- data/{xenon-routing/lib → lib}/xenon/routing/route_directives.rb +0 -0
- data/{xenon-routing/lib → lib}/xenon/routing/security_directives.rb +6 -0
- data/{xenon-routing/lib → lib}/xenon/routing_version.rb +0 -0
- data/{xenon-http/spec → spec}/spec_helper.rb +0 -0
- data/{xenon-routing/xenon-routing.gemspec → xenon-routing.gemspec} +2 -2
- metadata +25 -80
- data/.codeclimate.yml +0 -18
- data/.gitignore +0 -25
- data/.rspec +0 -3
- data/.travis.yml +0 -6
- data/Gemfile +0 -20
- data/Guardfile +0 -16
- data/LICENSE +0 -22
- data/README.md +0 -116
- data/Rakefile +0 -40
- data/VERSION +0 -1
- data/examples/hello_world/config.ru +0 -3
- data/examples/hello_world/hello_world.rb +0 -27
- data/xenon-http/lib/xenon/auth.rb +0 -63
- data/xenon-http/lib/xenon/errors.rb +0 -5
- data/xenon-http/lib/xenon/etag.rb +0 -48
- data/xenon-http/lib/xenon/headers.rb +0 -112
- data/xenon-http/lib/xenon/headers/accept.rb +0 -34
- data/xenon-http/lib/xenon/headers/accept_charset.rb +0 -59
- data/xenon-http/lib/xenon/headers/accept_encoding.rb +0 -63
- data/xenon-http/lib/xenon/headers/accept_language.rb +0 -59
- data/xenon-http/lib/xenon/headers/authorization.rb +0 -50
- data/xenon-http/lib/xenon/headers/cache_control.rb +0 -56
- data/xenon-http/lib/xenon/headers/content_type.rb +0 -23
- data/xenon-http/lib/xenon/headers/if_match.rb +0 -53
- data/xenon-http/lib/xenon/headers/if_modified_since.rb +0 -22
- data/xenon-http/lib/xenon/headers/if_none_match.rb +0 -53
- data/xenon-http/lib/xenon/headers/if_range.rb +0 -45
- data/xenon-http/lib/xenon/headers/if_unmodified_since.rb +0 -22
- data/xenon-http/lib/xenon/headers/user_agent.rb +0 -65
- data/xenon-http/lib/xenon/headers/www_authenticate.rb +0 -71
- data/xenon-http/lib/xenon/http.rb +0 -7
- data/xenon-http/lib/xenon/http_version.rb +0 -3
- data/xenon-http/lib/xenon/media_type.rb +0 -162
- data/xenon-http/lib/xenon/parsers/basic_rules.rb +0 -86
- data/xenon-http/lib/xenon/parsers/header_rules.rb +0 -60
- data/xenon-http/lib/xenon/parsers/media_type.rb +0 -53
- data/xenon-http/lib/xenon/quoted_string.rb +0 -20
- data/xenon-http/spec/xenon/etag_spec.rb +0 -19
- data/xenon-http/spec/xenon/headers/accept_charset_spec.rb +0 -31
- data/xenon-http/spec/xenon/headers/accept_encoding_spec.rb +0 -40
- data/xenon-http/spec/xenon/headers/accept_language_spec.rb +0 -33
- data/xenon-http/spec/xenon/headers/accept_spec.rb +0 -54
- data/xenon-http/spec/xenon/headers/authorization_spec.rb +0 -47
- data/xenon-http/spec/xenon/headers/cache_control_spec.rb +0 -64
- data/xenon-http/spec/xenon/headers/if_match_spec.rb +0 -73
- data/xenon-http/spec/xenon/headers/if_modified_since_spec.rb +0 -19
- data/xenon-http/spec/xenon/headers/if_none_match_spec.rb +0 -79
- data/xenon-http/spec/xenon/headers/if_range_spec.rb +0 -45
- data/xenon-http/spec/xenon/headers/if_unmodified_since_spec.rb +0 -19
- data/xenon-http/spec/xenon/headers/user_agent_spec.rb +0 -67
- data/xenon-http/spec/xenon/headers/www_authenticate_spec.rb +0 -43
- data/xenon-http/spec/xenon/media_type_spec.rb +0 -267
- data/xenon-http/xenon-http.gemspec +0 -25
- data/xenon-routing/spec/spec_helper.rb +0 -94
- data/xenon.gemspec +0 -26
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
require 'xenon/parsers/header_rules'
|
3
|
-
require 'xenon/parsers/media_type'
|
4
|
-
|
5
|
-
module Xenon
|
6
|
-
class Headers
|
7
|
-
# http://tools.ietf.org/html/rfc7231#section-5.3.2
|
8
|
-
class Accept < ListHeader 'Accept'
|
9
|
-
def initialize(*media_ranges)
|
10
|
-
super(media_ranges.sort_by.with_index { |mr, i| [mr, -i] }.reverse!)
|
11
|
-
end
|
12
|
-
|
13
|
-
alias_method :media_ranges, :values
|
14
|
-
|
15
|
-
def self.parse(s)
|
16
|
-
tree = Parsers::AcceptHeader.new.parse(s)
|
17
|
-
Parsers::AcceptHeaderTransform.new.apply(tree)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module Parsers
|
23
|
-
class AcceptHeader < Parslet::Parser
|
24
|
-
include HeaderRules, MediaTypeRules
|
25
|
-
rule(:accept) { (media_range >> (list_sep >> media_range).repeat).as(:accept) }
|
26
|
-
root(:accept)
|
27
|
-
end
|
28
|
-
|
29
|
-
class AcceptHeaderTransform < MediaTypeTransform
|
30
|
-
rule(accept: sequence(:mr)) { Headers::Accept.new(*mr) }
|
31
|
-
rule(accept: simple(:mr)) { Headers::Accept.new(mr) }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
require 'xenon/parsers/header_rules'
|
3
|
-
|
4
|
-
module Xenon
|
5
|
-
class CharsetRange
|
6
|
-
attr_reader :charset, :q
|
7
|
-
|
8
|
-
DEFAULT_Q = 1.0
|
9
|
-
|
10
|
-
def initialize(charset, q = DEFAULT_Q)
|
11
|
-
@charset = charset
|
12
|
-
@q = Float(q) || DEFAULT_Q
|
13
|
-
end
|
14
|
-
|
15
|
-
def <=>(other)
|
16
|
-
@q <=> other.q
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
s = @charset.dup
|
21
|
-
s << "; q=#{@q}" if @q != DEFAULT_Q
|
22
|
-
s
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Headers
|
27
|
-
# http://tools.ietf.org/html/rfc7231#section-5.3.3
|
28
|
-
class AcceptCharset < ListHeader 'Accept-Charset'
|
29
|
-
def initialize(*charset_ranges)
|
30
|
-
super(charset_ranges.sort_by.with_index { |mr, i| [mr, -i] }.reverse!)
|
31
|
-
end
|
32
|
-
|
33
|
-
alias_method :charset_ranges, :values
|
34
|
-
|
35
|
-
def self.parse(s)
|
36
|
-
tree = Parsers::AcceptCharsetHeader.new.parse(s)
|
37
|
-
Parsers::AcceptCharsetHeaderTransform.new.apply(tree)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module Parsers
|
43
|
-
class AcceptCharsetHeader < Parslet::Parser
|
44
|
-
include HeaderRules
|
45
|
-
rule(:charset) { token.as(:charset) >> sp? }
|
46
|
-
rule(:wildcard) { str('*').as(:charset) >> sp? }
|
47
|
-
rule(:charset_range) { (charset | wildcard) >> weight.maybe }
|
48
|
-
rule(:accept_charset) { (charset_range >> (list_sep >> charset_range).repeat).as(:accept_charset) }
|
49
|
-
root(:accept_charset)
|
50
|
-
end
|
51
|
-
|
52
|
-
class AcceptCharsetHeaderTransform < HeaderTransform
|
53
|
-
rule(charset: simple(:c), q: simple(:q)) { CharsetRange.new(c, q) }
|
54
|
-
rule(charset: simple(:c)) { CharsetRange.new(c) }
|
55
|
-
rule(accept_charset: sequence(:cr)) { Headers::AcceptCharset.new(*cr) }
|
56
|
-
rule(accept_charset: simple(:cr)) { Headers::AcceptCharset.new(cr) }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
require 'xenon/parsers/header_rules'
|
3
|
-
|
4
|
-
module Xenon
|
5
|
-
class ContentCodingRange
|
6
|
-
attr_reader :coding, :q
|
7
|
-
|
8
|
-
DEFAULT_Q = 1.0
|
9
|
-
|
10
|
-
def initialize(coding, q = DEFAULT_Q)
|
11
|
-
@coding = coding
|
12
|
-
@q = Float(q) || DEFAULT_Q
|
13
|
-
end
|
14
|
-
|
15
|
-
def <=>(other)
|
16
|
-
@q <=> other.q
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
s = @coding.dup
|
21
|
-
s << "; q=#{@q}" if @q != DEFAULT_Q
|
22
|
-
s
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Headers
|
27
|
-
# http://tools.ietf.org/html/rfc7231#section-5.3.4
|
28
|
-
class AcceptEncoding < ListHeader 'Accept-Encoding'
|
29
|
-
def initialize(*coding_ranges)
|
30
|
-
super(coding_ranges.sort_by.with_index { |mr, i| [mr, -i] }.reverse!)
|
31
|
-
end
|
32
|
-
|
33
|
-
alias_method :coding_ranges, :values
|
34
|
-
|
35
|
-
def self.parse(s)
|
36
|
-
tree = Parsers::AcceptEncodingHeader.new.parse(s)
|
37
|
-
Parsers::AcceptEncodingHeaderTransform.new.apply(tree)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module Parsers
|
43
|
-
class AcceptEncodingHeader < Parslet::Parser
|
44
|
-
include HeaderRules
|
45
|
-
%w(identity compress x-compress deflate gzip x-gzip).each do |c|
|
46
|
-
rule(c.tr('-', '_').to_sym) { str(c).as(:coding) >> sp? }
|
47
|
-
end
|
48
|
-
rule(:coding) { compress | x_compress | deflate | gzip | x_gzip }
|
49
|
-
rule(:wildcard) { str('*').as(:coding) >> sp? }
|
50
|
-
rule(:coding_range) { (coding | identity | wildcard) >> weight.maybe }
|
51
|
-
rule(:accept_encoding) { (coding_range >> (list_sep >> coding_range).repeat).maybe.as(:accept_encoding) }
|
52
|
-
root(:accept_encoding)
|
53
|
-
end
|
54
|
-
|
55
|
-
class AcceptEncodingHeaderTransform < HeaderTransform
|
56
|
-
rule(coding: simple(:c), q: simple(:q)) { ContentCodingRange.new(c, q) }
|
57
|
-
rule(coding: simple(:c)) { ContentCodingRange.new(c) }
|
58
|
-
rule(accept_encoding: sequence(:er)) { Headers::AcceptEncoding.new(*er) }
|
59
|
-
rule(accept_encoding: simple(:cc)) { Headers::AcceptEncoding.new(cc) }
|
60
|
-
rule(accept_encoding: nil) { Headers::AcceptEncoding.new }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
require 'xenon/parsers/header_rules'
|
3
|
-
|
4
|
-
module Xenon
|
5
|
-
class LanguageRange
|
6
|
-
attr_reader :language, :q
|
7
|
-
|
8
|
-
DEFAULT_Q = 1.0
|
9
|
-
|
10
|
-
def initialize(language, q = DEFAULT_Q)
|
11
|
-
@language = language
|
12
|
-
@q = Float(q) || DEFAULT_Q
|
13
|
-
end
|
14
|
-
|
15
|
-
def <=>(other)
|
16
|
-
@q <=> other.q
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
s = @language.dup
|
21
|
-
s << "; q=#{@q}" if @q != DEFAULT_Q
|
22
|
-
s
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Headers
|
27
|
-
# http://tools.ietf.org/html/rfc7231#section-5.3.5
|
28
|
-
class AcceptLanguage < ListHeader 'Accept-Language'
|
29
|
-
def initialize(*language_ranges)
|
30
|
-
super(language_ranges.sort_by.with_index { |mr, i| [mr, -i] }.reverse!)
|
31
|
-
end
|
32
|
-
|
33
|
-
alias_method :language_ranges, :values
|
34
|
-
|
35
|
-
def self.parse(s)
|
36
|
-
tree = Parsers::AcceptLanguageHeader.new.parse(s)
|
37
|
-
Parsers::AcceptLanguageHeaderTransform.new.apply(tree)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module Parsers
|
43
|
-
class AcceptLanguageHeader < Parslet::Parser
|
44
|
-
include HeaderRules
|
45
|
-
rule(:language) { (alpha.repeat(1, 8) >> (str('-') >> alphanum.repeat(1, 8)).maybe).as(:language) >> sp? }
|
46
|
-
rule(:wildcard) { str('*').as(:language) >> sp? }
|
47
|
-
rule(:language_range) { (language | wildcard) >> weight.maybe }
|
48
|
-
rule(:accept_language) { (language_range >> (list_sep >> language_range).repeat).as(:accept_language) }
|
49
|
-
root(:accept_language)
|
50
|
-
end
|
51
|
-
|
52
|
-
class AcceptLanguageHeaderTransform < HeaderTransform
|
53
|
-
rule(language: simple(:e), q: simple(:q)) { LanguageRange.new(e, q) }
|
54
|
-
rule(language: simple(:e)) { LanguageRange.new(e) }
|
55
|
-
rule(accept_language: sequence(:lr)) { Headers::AcceptLanguage.new(*lr) }
|
56
|
-
rule(accept_language: simple(:lr)) { Headers::AcceptLanguage.new(lr) }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'xenon/auth'
|
3
|
-
require 'xenon/headers'
|
4
|
-
require 'xenon/parsers/header_rules'
|
5
|
-
|
6
|
-
module Xenon
|
7
|
-
class Headers
|
8
|
-
# http://tools.ietf.org/html/rfc7235#section-4.2
|
9
|
-
class Authorization < Header 'Authorization'
|
10
|
-
attr_reader :credentials
|
11
|
-
|
12
|
-
def initialize(credentials)
|
13
|
-
@credentials = credentials
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.parse(s)
|
17
|
-
tree = Parsers::AuthorizationHeader.new.parse(s)
|
18
|
-
Parsers::AuthorizationHeaderTransform.new.apply(tree)
|
19
|
-
rescue Parslet::ParseFailed
|
20
|
-
raise Xenon::ParseError.new("Invalid Authorization header (#{s}).")
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
@credentials.to_s
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
module Parsers
|
30
|
-
class AuthorizationHeader < Parslet::Parser
|
31
|
-
include AuthHeaderRules
|
32
|
-
rule(:credentials) { auth_scheme >> sp >> (token68 | auth_params) }
|
33
|
-
rule(:authorization) { credentials.as(:authorization) }
|
34
|
-
root(:authorization)
|
35
|
-
end
|
36
|
-
|
37
|
-
class AuthorizationHeaderTransform < HeaderTransform
|
38
|
-
rule(auth_param: { name: simple(:n), value: simple(:v) }) { [n, v] }
|
39
|
-
rule(auth_params: subtree(:x)) { { foo: x } }
|
40
|
-
rule(auth_scheme: simple(:s), token: simple(:t)) {
|
41
|
-
case s
|
42
|
-
when 'Basic' then BasicCredentials.decode(t)
|
43
|
-
else GenericCredentials.new(s, token: t)
|
44
|
-
end
|
45
|
-
}
|
46
|
-
rule(auth_scheme: simple(:s), auth_params: subtree(:p)) { GenericCredentials.new(s, params: Hash[p]) }
|
47
|
-
rule(authorization: simple(:c)) { Headers::Authorization.new(c) }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
require 'xenon/parsers/header_rules'
|
3
|
-
require 'xenon/quoted_string'
|
4
|
-
|
5
|
-
module Xenon
|
6
|
-
class CacheDirective
|
7
|
-
using QuotedString
|
8
|
-
|
9
|
-
attr_reader :name, :value
|
10
|
-
|
11
|
-
def initialize(name, value = nil)
|
12
|
-
@name = name
|
13
|
-
@value = value
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
s = @name.dup
|
18
|
-
s << '=' << @value.quote if @value
|
19
|
-
s
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Headers
|
24
|
-
# http://tools.ietf.org/html/rfc7234#section-5.2
|
25
|
-
class CacheControl < ListHeader 'Cache-Control'
|
26
|
-
def initialize(*directives)
|
27
|
-
super(directives)
|
28
|
-
end
|
29
|
-
|
30
|
-
alias_method :directives, :values
|
31
|
-
|
32
|
-
def self.parse(s)
|
33
|
-
tree = Parsers::CacheControlHeader.new.parse(s)
|
34
|
-
Parsers::CacheControlHeaderTransform.new.apply(tree)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module Parsers
|
40
|
-
class CacheControlHeader < Parslet::Parser
|
41
|
-
include HeaderRules
|
42
|
-
rule(:name) { token.as(:name) }
|
43
|
-
rule(:value) { str('=') >> (token | quoted_string).as(:value) }
|
44
|
-
rule(:directive) { (name >> value.maybe).as(:directive) >> sp? }
|
45
|
-
rule(:cache_control) { (directive >> (list_sep >> directive).repeat).as(:cache_control) }
|
46
|
-
root(:cache_control)
|
47
|
-
end
|
48
|
-
|
49
|
-
class CacheControlHeaderTransform < HeaderTransform
|
50
|
-
rule(directive: { name: simple(:n), value: simple(:v) }) { CacheDirective.new(n, v) }
|
51
|
-
rule(directive: { name: simple(:n) }) { CacheDirective.new(n) }
|
52
|
-
rule(cache_control: sequence(:d)) { Headers::CacheControl.new(*d) }
|
53
|
-
rule(cache_control: simple(:d)) { Headers::CacheControl.new(d) }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
require 'xenon/media_type'
|
3
|
-
|
4
|
-
module Xenon
|
5
|
-
class Headers
|
6
|
-
# http://tools.ietf.org/html/rfc7231#section-3.1.1.5
|
7
|
-
class ContentType < Header 'Content-Type'
|
8
|
-
attr_reader :content_type
|
9
|
-
|
10
|
-
def initialize(content_type)
|
11
|
-
@content_type = content_type
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.parse(s)
|
15
|
-
new(Xenon::ContentType.parse(s))
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_s
|
19
|
-
@content_type.to_s
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
require 'xenon/parsers/header_rules'
|
3
|
-
require 'xenon/errors'
|
4
|
-
require 'xenon/etag'
|
5
|
-
|
6
|
-
module Xenon
|
7
|
-
class Headers
|
8
|
-
# http://tools.ietf.org/html/rfc7232#section-3.1
|
9
|
-
class IfMatch < ListHeader 'If-Match'
|
10
|
-
def initialize(*etags)
|
11
|
-
super(etags)
|
12
|
-
end
|
13
|
-
|
14
|
-
alias_method :etags, :values
|
15
|
-
|
16
|
-
def self.wildcard
|
17
|
-
new
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.parse(s)
|
21
|
-
tree = Parsers::IfMatchHeader.new.parse(s)
|
22
|
-
Parsers::IfMatchHeaderTransform.new.apply(tree)
|
23
|
-
end
|
24
|
-
|
25
|
-
def wildcard?
|
26
|
-
etags.empty?
|
27
|
-
end
|
28
|
-
|
29
|
-
def merge(other)
|
30
|
-
raise Xenon::ProtocolError.new('Cannot merge wildcard headers') if wildcard? || other.wildcard?
|
31
|
-
super
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
wildcard? ? '*' : super
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
module Parsers
|
41
|
-
class IfMatchHeader < Parslet::Parser
|
42
|
-
include ETagHeaderRules
|
43
|
-
rule(:if_match) { (wildcard | (etag >> (list_sep >> etag).repeat)).as(:if_match) }
|
44
|
-
root(:if_match)
|
45
|
-
end
|
46
|
-
|
47
|
-
class IfMatchHeaderTransform < ETagHeaderTransform
|
48
|
-
rule(if_match: { wildcard: simple(:w) }) { Headers::IfMatch.new }
|
49
|
-
rule(if_match: sequence(:et)) { Headers::IfMatch.new(*et) }
|
50
|
-
rule(if_match: simple(:et)) { Headers::IfMatch.new(et) }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
|
3
|
-
module Xenon
|
4
|
-
class Headers
|
5
|
-
# http://tools.ietf.org/html/rfc7232#section-3.3
|
6
|
-
class IfModifiedSince < Header 'If-Modified-Since'
|
7
|
-
attr_reader :date
|
8
|
-
|
9
|
-
def initialize(date)
|
10
|
-
@date = date
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.parse(s)
|
14
|
-
new(Time.httpdate(s))
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_s
|
18
|
-
@date.httpdate
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'xenon/headers'
|
2
|
-
require 'xenon/parsers/header_rules'
|
3
|
-
require 'xenon/errors'
|
4
|
-
require 'xenon/etag'
|
5
|
-
|
6
|
-
module Xenon
|
7
|
-
class Headers
|
8
|
-
# http://tools.ietf.org/html/rfc7232#section-3.2
|
9
|
-
class IfNoneMatch < ListHeader 'If-None-Match'
|
10
|
-
def initialize(*etags)
|
11
|
-
super(etags)
|
12
|
-
end
|
13
|
-
|
14
|
-
alias_method :etags, :values
|
15
|
-
|
16
|
-
def self.wildcard
|
17
|
-
new
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.parse(s)
|
21
|
-
tree = Parsers::IfNoneMatchHeader.new.parse(s)
|
22
|
-
Parsers::IfNoneMatchHeaderTransform.new.apply(tree)
|
23
|
-
end
|
24
|
-
|
25
|
-
def wildcard?
|
26
|
-
etags.empty?
|
27
|
-
end
|
28
|
-
|
29
|
-
def merge(other)
|
30
|
-
raise Xenon::ProtocolError.new('Cannot merge wildcard headers') if wildcard? || other.wildcard?
|
31
|
-
super
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
wildcard? ? '*' : super
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
module Parsers
|
41
|
-
class IfNoneMatchHeader < Parslet::Parser
|
42
|
-
include ETagHeaderRules
|
43
|
-
rule(:if_none_match) { (wildcard | (etag >> (list_sep >> etag).repeat)).as(:if_none_match) }
|
44
|
-
root(:if_none_match)
|
45
|
-
end
|
46
|
-
|
47
|
-
class IfNoneMatchHeaderTransform < ETagHeaderTransform
|
48
|
-
rule(if_none_match: { wildcard: simple(:w) }) { Headers::IfNoneMatch.new }
|
49
|
-
rule(if_none_match: sequence(:et)) { Headers::IfNoneMatch.new(*et) }
|
50
|
-
rule(if_none_match: simple(:et)) { Headers::IfNoneMatch.new(et) }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|