Class: ICAPrb::Server::BodyParser
- Inherits:
-
Object
- Object
- ICAPrb::Server::BodyParser
- Includes:
- Parser::ChunkedEncodingHelper
- Defined in:
- lib/icaprb/server/request_parser.rb
Overview
this class will parse an http body which has to be chunked encoded.
Instance Method Summary collapse
-
#initialize(io, read_everything = true, preview_header = nil) ⇒ BodyParser
constructor
By default, it will try to receive all data if the service does not provide information, if it supports previews.
-
#parse ⇒ Object
parses all chunks and concatenates then until: * the end of the preview is reached and the service is not correctly configured * die end of the data is reached it will return the data it got and if the ieof has been set.
Constructor Details
#initialize(io, read_everything = true, preview_header = nil) ⇒ BodyParser
By default, it will try to receive all data if the service does not provide information, if it supports previews. params:
io-
the Socket
read_everything-
read all data before forwarding them to the service - true by default (set a preview size in the service to override)
preview_header-
if a preview header is set, we can find out how long the preview will be. so we know how much data we can expect.
268 269 270 271 272 273 274 275 276 |
# File 'lib/icaprb/server/request_parser.rb', line 268 def initialize(io, read_everything = true, preview_header = nil) @io = io @read_everything = read_everything if preview_header @preview_size = preview_header.to_i else @preview_size = nil end end |
Instance Method Details
#parse ⇒ Object
parses all chunks and concatenates then until:
-
the end of the preview is reached and the service is not correctly configured
-
die end of the data is reached
it will return the data it got and if the ieof has been set.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/icaprb/server/request_parser.rb', line 282 def parse data = '' ieof = false until (line,ieof = read_chunk(@io); line) && line == :eof data += line end if !ieof && @read_everything && !@preview_size.nil? && (@preview_size >= data.length) Response.continue(@io) until (line,ieof2 = read_chunk(@io); line) && line == :eof data += line ieof ||= ieof2 end end return data, ieof end |