Changeset 09fef40cac145611c80b1048abd0fbcbd2a6cd70
- Timestamp:
- 10/31/11 18:02:41
(2 years ago)
- Author:
- Ryan Phillips <ryan.phillips@rackspace.com>
- git-committer:
- Ryan Phillips <ryan.phillips@rackspace.com> 1320084161 -0500
- git-parent:
[f5982323e614fec6b6ca1900cedb708f89020355]
- git-author:
- Ryan Phillips <ryan.phillips@rackspace.com> 1319738416 -0500
- Message:
add support for check config option read_limit
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rf598232 |
r09fef40 |
|
| 130 | 130 | end |
|---|
| 131 | 131 | |
|---|
| 132 | | function te_length(self, content_enc_func) |
|---|
| | 132 | function te_length(self, content_enc_func, read_limit) |
|---|
| 133 | 133 | local len = tonumber(self.headers["content-length"]) |
|---|
| 134 | | len = len > 102400 and 102400 or len |
|---|
| | 134 | if read_limit > 0 and len > read_limit then |
|---|
| | 135 | len = read_limit |
|---|
| | 136 | end |
|---|
| 135 | 137 | repeat |
|---|
| 136 | 138 | local str = self.e:read(len) |
|---|
| … | … | |
| 145 | 147 | end |
|---|
| 146 | 148 | |
|---|
| 147 | | function te_chunked(self, content_enc_func) |
|---|
| | 149 | function te_chunked(self, content_enc_func, read_limit) |
|---|
| 148 | 150 | while true do |
|---|
| 149 | 151 | local str = self.e:read("\n") |
|---|
| … | … | |
| 162 | 164 | self.content_bytes = self.content_bytes + string.len(decoded) |
|---|
| 163 | 165 | if self.hooks.consume ~= nil then self.hooks.consume(decoded) end |
|---|
| | 166 | if read_limit > 0 then |
|---|
| | 167 | if string.len(self.content_bytes) > read_limit then |
|---|
| | 168 | return |
|---|
| | 169 | end |
|---|
| | 170 | end |
|---|
| 164 | 171 | -- each chunk ('cept a 0 size one) is followed by a \r\n |
|---|
| 165 | 172 | str = self.e:read("\n") |
|---|
| 166 | 173 | if str ~= "\r\n" and str ~= "\n" then error("short chunked boundary read") end |
|---|
| 167 | | if string.len(self.content_bytes) > 102400 then |
|---|
| 168 | | break |
|---|
| 169 | | end |
|---|
| 170 | 174 | end |
|---|
| 171 | 175 | -- read trailers |
|---|
| … | … | |
| 177 | 181 | end |
|---|
| 178 | 182 | |
|---|
| 179 | | function HttpClient:get_body() |
|---|
| | 183 | function HttpClient:get_body(read_limit) |
|---|
| 180 | 184 | local cefunc = ce_passthru |
|---|
| 181 | 185 | local ce = self.headers["content-encoding"] |
|---|
| … | … | |
| 192 | 196 | local cl = self.headers["content-length"] |
|---|
| 193 | 197 | if te ~= nil and te == "chunked" then |
|---|
| 194 | | return te_chunked(self, cefunc) |
|---|
| | 198 | return te_chunked(self, cefunc, read_limit) |
|---|
| 195 | 199 | elseif cl ~= nil and tonumber(cl) ~= nil then |
|---|
| 196 | | return te_length(self, cefunc) |
|---|
| | 200 | return te_length(self, cefunc, read_limit) |
|---|
| 197 | 201 | end |
|---|
| 198 | 202 | return te_close(self, cefunc) |
|---|
| 199 | 203 | end |
|---|
| 200 | 204 | |
|---|
| 201 | | function HttpClient:get_response() |
|---|
| | 205 | function HttpClient:get_response(read_limit) |
|---|
| 202 | 206 | self:get_headers() |
|---|
| 203 | | return self:get_body() |
|---|
| | 207 | return self:get_body(read_limit) |
|---|
| 204 | 208 | end |
|---|
| 205 | 209 | |
|---|
| ra24b166 |
r09fef40 |
|
| 92 | 92 | default="10000" |
|---|
| 93 | 93 | allowed="\d+">This sets the PCRE internal match limit (see pcreapi documentation).</parameter> |
|---|
| | 94 | <parameter name="read_limit" |
|---|
| | 95 | required="optional" |
|---|
| | 96 | default="102400" |
|---|
| | 97 | allowed="\d+">Sets the limit on the data read.</parameter> |
|---|
| 94 | 98 | </checkconfig> |
|---|
| 95 | 99 | <examples> |
|---|
| … | … | |
| 270 | 274 | local pcre_match_limit = check.config.pcre_match_limit or 10000 |
|---|
| 271 | 275 | local redirects = check.config.redirects or 0 |
|---|
| | 276 | local read_limit = check.config.read_limit or 10 |
|---|
| 272 | 277 | |
|---|
| 273 | 278 | -- expect the worst |
|---|
| … | … | |
| 354 | 359 | end |
|---|
| 355 | 360 | client:do_request(method, uri, headers_firstpass) |
|---|
| 356 | | client:get_response() |
|---|
| | 361 | client:get_response(read_limit) |
|---|
| 357 | 362 | if client.code ~= 401 or |
|---|
| 358 | 363 | client.headers["www-authenticate"] == nil then |
|---|
| … | … | |
| 397 | 402 | end |
|---|
| 398 | 403 | optclient:do_request(method, uri, headers, payload) |
|---|
| 399 | | optclient:get_response() |
|---|
| | 404 | optclient:get_response(read_limit) |
|---|
| 400 | 405 | |
|---|
| 401 | 406 | redirects = redirects - 1 |
|---|