class Net::HTTP::Server::Stream
Handles reading and writing to raw HTTP
streams.
@since 0.2.0
Attributes
socket[R]
The raw socket of the stream.
Public Class Methods
new(socket)
click to toggle source
Creates a new stream.
@param [TCPSocket] socket
The raw socket that will be read/write to.
@since 0.2.0
# File lib/net/http/server/stream.rb, line 26 def initialize(socket) @socket = socket end
Public Instance Methods
<<(data)
click to toggle source
body()
click to toggle source
Reads the entire body.
@return [String]
The complete body.
@since 0.2.0
# File lib/net/http/server/stream.rb, line 78 def body buffer = '' each { |chunk| buffer << chunk } return buffer end
close()
click to toggle source
Closes the stream.
@since 0.2.0
# File lib/net/http/server/stream.rb, line 117 def close end
each() { |chunk| ... }
click to toggle source
Reads each chunk from the stream.
@yield [chunk]
The given block will be passed each chunk.
@yieldparam [String] chunk
A chunk from the stream.
@return [Enumerator]
If no block is given, an Enumerator will be returned.
@since 0.2.0
# File lib/net/http/server/stream.rb, line 62 def each return enum_for unless block_given? while (chunk = read) yield chunk end end
read(length=4096,buffer='')
click to toggle source
Reads data from the stream.
@param [Integer] length
The number of bytes to read.
@param [#<<] buffer
The optional buffer to append the data to.
@return [String, nil]
A chunk from the stream.
@since 0.2.0
# File lib/net/http/server/stream.rb, line 44 def read(length=4096,buffer='') @socket.read(length,buffer) end
write(data)
click to toggle source
Writes data to the stream.
@param [String] data
The data to write to the stream.
@return [Integer]
The length of the data written.
@since 0.2.0
# File lib/net/http/server/stream.rb, line 96 def write(data) result = @socket.write(data) @socket.flush return result end