Class: HTTP::Security::Parsers::Parser
- Inherits:
-
Parslet::Parser
- Object
- Parslet::Parser
- HTTP::Security::Parsers::Parser
show all
- Defined in:
- lib/http/security/parsers/parser.rb
Direct Known Subclasses
CacheControl, ContentSecurityPolicy, Expires, Pragma, PublicKeyPins, SetCookie, StrictTransportSecurity, XContentTypeOptions, XFrameOptions, XPermittedCrossDomainPolicies, XXSSProtection
Defined Under Namespace
Classes: Transform
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.character_match_rule(name, character) ⇒ Object
10
11
12
13
14
|
# File 'lib/http/security/parsers/parser.rb', line 10
def self.character_match_rule(name, character)
rule(name) do
wsp? >> str(character) >> wsp?
end
end
|
.directive_rule(name, string = nil) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/http/security/parsers/parser.rb', line 16
def self.directive_rule(name,string=nil)
string ||= name.to_s.tr('_','-')
rule(name) do
stri(string).as(:key)
end
end
|
.field_directive_rule(name, directive) ⇒ Object
24
25
26
27
28
|
# File 'lib/http/security/parsers/parser.rb', line 24
def self.field_directive_rule(name,directive)
rule(name) do
stri(directive).as(:key) >> (equals >> field_name.as(:value)).maybe
end
end
|
.numeric_directive_rule(name, directive) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/http/security/parsers/parser.rb', line 30
def self.numeric_directive_rule(name,directive)
rule(name) do
stri(directive).as(:key) >> equals >> (
digits.as(:numeric) |
(s_quote >> digits.as(:numeric) >> s_quote) |
(d_quote >> digits.as(:numeric) >> d_quote)
).as(:value)
end
end
|
.parse(string) ⇒ Object
401
402
403
|
# File 'lib/http/security/parsers/parser.rb', line 401
def self.parse(string)
new.parse(string)
end
|
Instance Method Details
#parse(string) ⇒ Object
397
398
399
|
# File 'lib/http/security/parsers/parser.rb', line 397
def parse(string)
Transform.new.apply(super(string))
end
|
#stri(str) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/http/security/parsers/parser.rb', line 40
def stri(str)
key_chars = str.split(//)
key_chars.collect! do |char|
if char.eql?("-")
match["#{Regexp.escape("\x2d")}"]
else
match["#{char.upcase}#{char.downcase}"]
end
end
key_chars.reduce(:>>)
end
|