Class: Net::HTTP::Server::Stream
- Inherits:
-
Object
- Object
- Net::HTTP::Server::Stream
- Includes:
- Enumerable
- Defined in:
- lib/net/http/server/stream.rb
Overview
Handles reading and writing to raw HTTP streams.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
The raw socket of the stream.
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#body ⇒ String
Reads the entire body.
-
#close ⇒ Object
Closes the stream.
-
#each {|chunk| ... } ⇒ Enumerator
Reads each chunk from the stream.
-
#initialize(socket) ⇒ Stream
constructor
Creates a new stream.
-
#read(length = 4096, buffer = '') ⇒ String?
Reads data from the stream.
-
#write(data) ⇒ Integer
Writes data to the stream.
Constructor Details
#initialize(socket) ⇒ Stream
Creates a new stream.
26 27 28 |
# File 'lib/net/http/server/stream.rb', line 26 def initialize(socket) @socket = socket end |
Instance Attribute Details
#socket ⇒ Object (readonly)
The raw socket of the stream.
16 17 18 |
# File 'lib/net/http/server/stream.rb', line 16 def socket @socket end |
Instance Method Details
#<<(data) ⇒ Object
108 109 110 |
# File 'lib/net/http/server/stream.rb', line 108 def <<(data) write(data) end |
#body ⇒ String
Reads the entire body.
78 79 80 81 82 83 |
# File 'lib/net/http/server/stream.rb', line 78 def body buffer = '' each { |chunk| buffer << chunk } return buffer end |
#close ⇒ Object
Closes the stream.
117 118 |
# File 'lib/net/http/server/stream.rb', line 117 def close end |
#each {|chunk| ... } ⇒ Enumerator
Reads each chunk from the stream.
62 63 64 65 66 67 68 |
# 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 = '') ⇒ String?
Reads data from the stream.
44 45 46 |
# File 'lib/net/http/server/stream.rb', line 44 def read(length=4096,buffer='') @socket.read(length,buffer) end |
#write(data) ⇒ Integer
Writes data to the stream.
96 97 98 99 100 101 |
# File 'lib/net/http/server/stream.rb', line 96 def write(data) result = @socket.write(data) @socket.flush return result end |