lowloop 0.8.18 → 0.8.19
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.
- checksums.yaml +4 -4
- data/lib/connections/connection_manager.rb +36 -8
- data/lib/connections/request_parser.rb +2 -2
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bfa90ecaa4270aadf325053b4e2e50c20a6c93339ec59e58a6739fd7752c9486
|
|
4
|
+
data.tar.gz: 8254d17ed1aca9301aa8216bd61897f0bf634297284002f820f1dbcbf367c0cb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6eb1fa0d79dc9a290f16035f9c13466195c473188084de9c8f15f12d9fa63fb4baec8447d175c52305c561294b17fdf54dee92f1d1cd4df5451e6698ab4f81d8
|
|
7
|
+
data.tar.gz: 7665d750b778779fb72ebfce139a8cc30e3e844ab92f009b6f05cf0c8cb5703c8138f84203b6ed75cc33ac282c857b676730e698d986a4ec46f93ef9ee4649d0
|
|
@@ -74,17 +74,36 @@ module Low
|
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
#
|
|
77
|
+
# The Connection header is read from the request's fields, as reading it with "request.headers['connection']" would
|
|
78
|
+
# index and parse every header. Its tokens, like "keep-alive, Upgrade", are matched in any case.
|
|
78
79
|
def keep_alive?(request)
|
|
79
|
-
tokens = request.headers['connection']
|
|
80
|
-
|
|
81
80
|
if request.version.to_s.include?('1.0')
|
|
82
|
-
|
|
81
|
+
connection?(request, KEEP_ALIVE_TOKEN)
|
|
83
82
|
else
|
|
84
|
-
!
|
|
83
|
+
!connection?(request, CLOSE_TOKEN)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
KEEP_ALIVE_TOKEN = /(?:\A|,)\s*keep-alive\s*(?:,|\z)/i
|
|
88
|
+
CLOSE_TOKEN = /(?:\A|,)\s*close\s*(?:,|\z)/i
|
|
89
|
+
|
|
90
|
+
# Header names are ASCII, so they're compared with casecmp, as casecmp? folds Unicode case into new strings.
|
|
91
|
+
def connection?(request, token)
|
|
92
|
+
request.headers.fields.any? do |name, value|
|
|
93
|
+
name = name.to_s
|
|
94
|
+
name.length == 10 && name.casecmp('connection') == 0 && value.to_s.match?(token) # rubocop:disable Style/NumericPredicate
|
|
85
95
|
end
|
|
86
96
|
end
|
|
87
97
|
|
|
98
|
+
# Each header name in lowercase, made once for each name, as most requests send the same few. Only so many are kept,
|
|
99
|
+
# as a client can send any name.
|
|
100
|
+
DOWNCASED = {} # rubocop:disable Style/MutableConstant
|
|
101
|
+
DOWNCASED_LIMIT = 1000
|
|
102
|
+
|
|
103
|
+
def downcased(name)
|
|
104
|
+
DOWNCASED[name] || (DOWNCASED.size < DOWNCASED_LIMIT ? DOWNCASED[name.dup.freeze] = name.downcase.freeze : name.downcase)
|
|
105
|
+
end
|
|
106
|
+
|
|
88
107
|
def keep_alive_timeout
|
|
89
108
|
config.keep_alive_timeout || DEFAULT_KEEP_ALIVE_TIMEOUT
|
|
90
109
|
end
|
|
@@ -94,11 +113,20 @@ module Low
|
|
|
94
113
|
end
|
|
95
114
|
|
|
96
115
|
# Headers there can only be one of, like Referer, raise when read if a request repeats them, so it's a bad request.
|
|
116
|
+
# They're those without a policy for joining them in Protocol::HTTP, which is checked by name, rather than indexing
|
|
117
|
+
# and parsing every header with "to_h" before anything reads them.
|
|
97
118
|
def headers_valid?(request)
|
|
98
|
-
|
|
119
|
+
seen = nil
|
|
120
|
+
request.headers.fields.each do |field|
|
|
121
|
+
key = downcased(field.first.to_s)
|
|
122
|
+
next if Protocol::HTTP::Headers::POLICY[key]
|
|
123
|
+
|
|
124
|
+
seen ||= {}
|
|
125
|
+
return false if seen.key?(key)
|
|
126
|
+
|
|
127
|
+
seen[key] = true
|
|
128
|
+
end
|
|
99
129
|
true
|
|
100
|
-
rescue Protocol::HTTP::InvalidHeaderError
|
|
101
|
-
false
|
|
102
130
|
end
|
|
103
131
|
|
|
104
132
|
private
|
|
@@ -59,7 +59,7 @@ module Low
|
|
|
59
59
|
method_end = request_line.index(' ') || request_line.length
|
|
60
60
|
path_end = request_line.index(' ', method_end + 1) || request_line.length
|
|
61
61
|
|
|
62
|
-
[request_line[0, method_end], request_line[method_end + 1
|
|
62
|
+
[request_line[0, method_end], request_line[method_end + 1, path_end - method_end - 1]]
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def parse_headers(stream: IO::Stream::Generic) -> { ::Protocol::HTTP::Headers }
|
|
@@ -74,7 +74,7 @@ module Low
|
|
|
74
74
|
colon = line.index(':')
|
|
75
75
|
next fields << [line, +''] unless colon
|
|
76
76
|
|
|
77
|
-
value = line[colon + 1
|
|
77
|
+
value = line[colon + 1, line.length]
|
|
78
78
|
value.strip!
|
|
79
79
|
fields << [line[0, colon], value]
|
|
80
80
|
end
|
data/lib/version.rb
CHANGED