Changeset aed22aaeceba5be6d574a0721d482578a3e4e74f

Show
Ignore:
Timestamp:
11/09/11 13:24:24 (2 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1320845064 -0500
git-parent:

[fbf2b3181e1cc48410fe39bb0f0c291d73095a8f], [61903febed2d9becbc4659f7d3cde0e19ae87d14]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1320845064 -0500
Message:

Merge branch 'http_length' of https://github.com/rphillips/reconnoiter into http_length

There was a bug in http chunked encoding where the limits were never
enforced. Also, the default was set to no limit to emulate previous
behaviour.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules-lua/noit/HttpClient.lua

    r801a7a7 raed22aa  
    4444    self.target = target 
    4545    self.port = port 
     46    self.truncated = nil 
    4647    local rv, err = self.e:connect(self.target, self.port) 
    4748    if rv ~= 0 then 
     
    130131end 
    131132 
    132 function te_length(self, content_enc_func
     133function te_length(self, content_enc_func, read_limit
    133134    local len = tonumber(self.headers["content-length"]) 
     135    if read_limit and read_limit > 0 and len > read_limit then 
     136      len = read_limit 
     137      self.truncated = true 
     138    end 
    134139    repeat 
    135140        local str = self.e:read(len) 
     
    144149end 
    145150 
    146 function te_chunked(self, content_enc_func
     151function te_chunked(self, content_enc_func, read_limit
    147152    while true do 
    148153        local str = self.e:read("\n") 
     
    161166        self.content_bytes = self.content_bytes + string.len(decoded) 
    162167        if self.hooks.consume ~= nil then self.hooks.consume(decoded) end 
     168        if read_limit and read_limit > 0 then 
     169          if self.content_bytes > read_limit then 
     170            self.truncated = true 
     171            return 
     172          end 
     173        end 
    163174        -- each chunk ('cept a 0 size one) is followed by a \r\n 
    164175        str = self.e:read("\n") 
     
    173184end 
    174185 
    175 function HttpClient:get_body(
     186function HttpClient:get_body(read_limit
    176187    local cefunc = ce_passthru 
    177188    local ce = self.headers["content-encoding"] 
     
    188199    local cl = self.headers["content-length"] 
    189200    if te ~= nil and te == "chunked" then 
    190         return te_chunked(self, cefunc
     201        return te_chunked(self, cefunc, read_limit
    191202    elseif cl ~= nil and tonumber(cl) ~= nil then 
    192         return te_length(self, cefunc
     203        return te_length(self, cefunc, read_limit
    193204    end 
    194205    return te_close(self, cefunc) 
    195206end 
    196207 
    197 function HttpClient:get_response(
     208function HttpClient:get_response(read_limit
    198209    self:get_headers() 
    199     return self:get_body(
     210    return self:get_body(read_limit
    200211end 
    201212 
  • src/modules-lua/noit/module/http.lua

    r3d84df2 raed22aa  
    9696               allowed="^(?:true|false|on|off)$" 
    9797               default="false">Include whole response body as a metric with the key 'body'.</parameter> 
    98  
     98    <parameter name="read_limit" 
     99               required="optional" 
     100               default="0" 
     101               allowed="\d+">Sets an approximate limit on the data read (0 means no limit).</parameter> 
    99102  </checkconfig> 
    100103  <examples> 
     
    276279    local redirects = check.config.redirects or 0 
    277280    local include_body = false 
     281    local read_limit = tonumber(check.config.read_limit) or 0 
    278282 
    279283    -- expect the worst 
     
    365369        end 
    366370        client:do_request(method, uri, headers_firstpass) 
    367         client:get_response(
     371        client:get_response(read_limit
    368372        if client.code ~= 401 or 
    369373           client.headers["www-authenticate"] == nil then 
     
    408412        end 
    409413        optclient:do_request(method, uri, headers, payload) 
    410         optclient:get_response(
     414        optclient:get_response(read_limit
    411415 
    412416        redirects = redirects - 1 
     
    458462    end 
    459463 
     464    -- truncated response 
     465    check.metric_uint32("truncated", client.truncated and 1 or 0) 
     466 
    460467    -- turnaround time 
    461468    local seconds = elapsed(check, "duration", starttime, endtime)