Class: Uma::HTTP::RackIO
- Inherits:
-
Object
- Object
- Uma::HTTP::RackIO
- Defined in:
- lib/uma/http.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each ⇒ Object
- #gets ⇒ Object
-
#initialize(env, stream) ⇒ RackIO
constructor
A new instance of RackIO.
- #puts(str) ⇒ Object
- #read(len, buf = +'')) ⇒ Object
- #read_chunks ⇒ Object
- #write(*bufs) ⇒ Object (also: #<<)
Constructor Details
#initialize(env, stream) ⇒ RackIO
Returns a new instance of RackIO.
10 11 12 13 14 15 |
# File 'lib/uma/http.rb', line 10 def initialize(env, stream) @env = env @stream = stream @machine = stream.machine @fd = stream.fd end |
Instance Method Details
#close ⇒ Object
47 48 49 |
# File 'lib/uma/http.rb', line 47 def close @machine.close(@fd) end |
#each ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/uma/http.rb', line 25 def each(&) if @env['HTTP_TRANSFER_ENCODING'] == 'chunked' read_chunks(&) elsif (v = @env['CONTENT_LENGTH']) len = v.to_i yield @stream.get_string(+'', len) end end |
#gets ⇒ Object
17 18 19 |
# File 'lib/uma/http.rb', line 17 def gets @stream.get_line(nil, 0) end |
#puts(str) ⇒ Object
51 52 53 |
# File 'lib/uma/http.rb', line 51 def puts(str) write("#{str}\n") end |
#read(len, buf = +'')) ⇒ Object
21 22 23 |
# File 'lib/uma/http.rb', line 21 def read(len, buf = +'') @stream.get_string(buf, -30) end |
#read_chunks ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/uma/http.rb', line 34 def read_chunks buf = +'' while true line = @stream.get_line(buf, 8) len = line.to_i(16) break if len == 0 chunk = @stream.get_string(nil, len) yield chunk @stream.skip(2) end end |
#write(*bufs) ⇒ Object Also known as: <<
55 56 57 |
# File 'lib/uma/http.rb', line 55 def write(*bufs) @machine.writev(@fd, *bufs) end |