Class: Net::AJP13::Server::BodyInput
- Inherits:
-
Object
- Object
- Net::AJP13::Server::BodyInput
- Includes:
- Enumerable, Constants
- Defined in:
- lib/net/ajp13server.rb
Overview
Input stream that corresponds the request body from the web server. BodyInput object acts as an IO except writing methods.
Constant Summary collapse
- GETS_BLOCK_SIZE =
:nodoc:
256
Instance Attribute Summary collapse
-
#length ⇒ Object
(also: #size)
readonly
Content-Length.
Instance Method Summary collapse
-
#binmode ⇒ Object
Does nothing.
-
#clone ⇒ Object
(also: #dup)
Raises TypeError.
-
#close ⇒ Object
(also: #close_read)
Closes the BodyInput.
-
#closed? ⇒ Boolean
Returns true if the BodyInput is closed.
-
#each_byte ⇒ Object
Same as IO#each_byte.
- #each_line(rs = $/) ⇒ Object (also: #each)
- #eof? ⇒ Boolean (also: #eof)
-
#fcntl(*args) ⇒ Object
Raises NotImplementedError.
-
#fileno ⇒ Object
(also: #to_i)
Always returns nil.
- #getc ⇒ Object
- #gets(rs = $/) ⇒ Object
-
#initialize(sock, length) ⇒ BodyInput
constructor
sock- socket connection to the web server
length -
Content-Length.
- socket connection to the web server
-
#iocntl(*args) ⇒ Object
Raises NotImplementedError.
-
#isatty ⇒ Object
(also: #tty?)
Returns false.
- #lineno ⇒ Object
-
#pid ⇒ Object
Returns nil.
-
#pos ⇒ Object
(also: #tell)
Returns current read position.
-
#read(length = nil, buf = '') ⇒ Object
(also: #sysread)
:args: [length[, buf]].
- #readchar ⇒ Object
- #readline(rs = $/) ⇒ Object
-
#reopen(*args) ⇒ Object
Raises NotImplementedError.
- #sync ⇒ Object
- #sync=(val) ⇒ Object
-
#to_io ⇒ Object
Returns self.
- #ungetc(char) ⇒ Object
Constructor Details
Instance Attribute Details
#length ⇒ Object (readonly) Also known as: size
Content-Length
248 249 250 |
# File 'lib/net/ajp13server.rb', line 248 def length @length end |
Instance Method Details
#binmode ⇒ Object
Does nothing
252 |
# File 'lib/net/ajp13server.rb', line 252 def binmode; self end |
#clone ⇒ Object Also known as: dup
Raises TypeError. You can’t clone BodyInput.
255 256 257 |
# File 'lib/net/ajp13server.rb', line 255 def clone raise TypeError, "can't clone #{self.class}" end |
#close ⇒ Object Also known as: close_read
Closes the BodyInput. Note that this method does not close the internal socket connection.
262 263 264 |
# File 'lib/net/ajp13server.rb', line 262 def close @packet = @sock = nil end |
#closed? ⇒ Boolean
Returns true if the BodyInput is closed.
267 268 269 |
# File 'lib/net/ajp13server.rb', line 267 def closed? @sock.nil? end |
#each_byte ⇒ Object
Same as IO#each_byte
273 274 275 276 277 |
# File 'lib/net/ajp13server.rb', line 273 def each_byte while ch = getc yield ch end end |
#each_line(rs = $/) ⇒ Object Also known as: each
401 402 403 404 405 |
# File 'lib/net/ajp13server.rb', line 401 def each_line(rs = $/) while line = gets(rs) yield line end end |
#eof? ⇒ Boolean Also known as: eof
279 280 281 |
# File 'lib/net/ajp13server.rb', line 279 def eof? @read_length >= @length end |
#fcntl(*args) ⇒ Object
Raises NotImplementedError
285 286 287 |
# File 'lib/net/ajp13server.rb', line 285 def fcntl(*args) raise NotImplementedError, "#{self} does not support fcntl" end |
#fileno ⇒ Object Also known as: to_i
Always returns nil
294 |
# File 'lib/net/ajp13server.rb', line 294 def fileno; nil end |
#getc ⇒ Object
297 298 299 300 |
# File 'lib/net/ajp13server.rb', line 297 def getc str = read(1) str and str[0] end |
#gets(rs = $/) ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/net/ajp13server.rb', line 373 def gets(rs = $/) return read if rs.nil? @lineno ||= 0 @line ||= '' pattern = /\A.+?#{rs=='' ? "\\r?\\n\\r?\\n" : Regexp.escape(rs)}/ until md = pattern.match(@line) block = read(GETS_BLOCK_SIZE) if block.nil? line = @line @line = nil @lineno += 1 return line == '' ? nil : line else @line << block end end @line = md.post_match @lineno += 1 return md.to_s end |
#iocntl(*args) ⇒ Object
Raises NotImplementedError
289 290 291 |
# File 'lib/net/ajp13server.rb', line 289 def iocntl(*args) raise NotImplementedError, "#{self} does not support iocntl" end |
#isatty ⇒ Object Also known as: tty?
Returns false
303 |
# File 'lib/net/ajp13server.rb', line 303 def isatty; false end |
#lineno ⇒ Object
306 |
# File 'lib/net/ajp13server.rb', line 306 def lineno; @lineno end |
#pid ⇒ Object
Returns nil
309 |
# File 'lib/net/ajp13server.rb', line 309 def pid; nil end |
#pos ⇒ Object Also known as: tell
Returns current read position.
312 |
# File 'lib/net/ajp13server.rb', line 312 def pos; @read_length end |
#read(length = nil, buf = '') ⇒ Object Also known as: sysread
:args: [length[, buf]]
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/net/ajp13server.rb', line 315 def read(length = nil, buf = '') #:args: [length[, buf]] raise TypeError, "can't modify frozen stream" if frozen? raise IOError, 'closed stream' if closed? if length.nil? return '' if eof? length = [0, @length - @read_length].max else raise ArgumentError, "negative length #{length} given" if length < 0 if eof? buf[0..-1] = '' return nil end end if @packet.eof? written_length = 0 else chunk = @packet.read_bytes(length) written_length = chunk.length @read_length += written_length buf[0, written_length] = chunk end while written_length < length and !eof? packet = Net::AJP13::Packet.new packet.direction = :from_app packet.append_byte GET_BODY_CHUNK packet.append_integer [@length - @read_length, MAX_BODY_CHUNK_SIZE].min packet.send_to @sock @packet = Net::AJP13::Packet.from_io(@sock) if @packet.length == 0 # this means eof break else chunk = @packet.read_bytes(length - written_length) buf[written_length, chunk.length] = chunk written_length += chunk.length @read_length += chunk.length end end if written_length < buf.length buf[written_length..-1] = '' end return buf end |
#readchar ⇒ Object
363 364 365 366 367 368 369 370 |
# File 'lib/net/ajp13server.rb', line 363 def readchar str = read(1) if str.nil? raise EOFError else str[0] end end |
#readline(rs = $/) ⇒ Object
393 394 395 396 397 398 399 400 |
# File 'lib/net/ajp13server.rb', line 393 def readline(rs = $/) line = gets(rs) if line.nil? raise EOFError else line end end |
#reopen(*args) ⇒ Object
Raises NotImplementedError
409 410 411 |
# File 'lib/net/ajp13server.rb', line 409 def reopen(*args) raise NotImplementedError, "#{self.class} does not support reopen" end |
#sync ⇒ Object
413 |
# File 'lib/net/ajp13server.rb', line 413 def sync; @sock.sync end |
#sync=(val) ⇒ Object
414 |
# File 'lib/net/ajp13server.rb', line 414 def sync=(val); @sock.sync = val end |
#to_io ⇒ Object
Returns self
419 |
# File 'lib/net/ajp13server.rb', line 419 def to_io; self end |
#ungetc(char) ⇒ Object
421 422 423 424 425 426 427 428 |
# File 'lib/net/ajp13server.rb', line 421 def ungetc(char) raise TypeError, "#{char} is not a Fixnum" unless char.is_a? Fixnum raise ArgumentError, "#{char} must be a byte, but negative" if char < 0 raise ArgumentError, "#{char} is too large to treat as a byte" if char > 0xFF @packet.unread_byte(char) @read_length -= 1 nil end |