Class: Net::HTTP::SPDY::Stream
- Inherits:
-
Object
- Object
- Net::HTTP::SPDY::Stream
- Extended by:
- Forwardable
- Defined in:
- lib/net/http/spdy/stream.rb
Instance Attribute Summary collapse
-
#assocs ⇒ Object
readonly
Returns the value of attribute assocs.
-
#buf ⇒ Object
Returns the value of attribute buf.
-
#connected ⇒ Object
Returns the value of attribute connected.
-
#eof ⇒ Object
Returns the value of attribute eof.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#new_assoc ⇒ Object
Returns the value of attribute new_assoc.
-
#sock ⇒ Object
readonly
Returns the value of attribute sock.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #close_write ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(id, session, sock, uri) ⇒ Stream
constructor
A new instance of Stream.
- #read(len, dest = '', ignore_eof = false) ⇒ Object
- #read_all(dest = '') ⇒ Object
- #readline ⇒ Object
- #readuntil(terminator, ignore_eof = false) ⇒ Object
- #write(buf) ⇒ Object (also: #<<)
- #write_headers(method, path, ver, request) ⇒ Object
- #write_protocol_error ⇒ Object
Constructor Details
#initialize(id, session, sock, uri) ⇒ Stream
Returns a new instance of Stream.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/net/http/spdy/stream.rb', line 10 def initialize(id, session, sock, uri) @id = id @session = session @sock = sock @buf = "" @eof = false @uri = uri @assocs = [] @new_assoc = nil @connected = false end |
Instance Attribute Details
#assocs ⇒ Object (readonly)
Returns the value of attribute assocs.
7 8 9 |
# File 'lib/net/http/spdy/stream.rb', line 7 def assocs @assocs end |
#buf ⇒ Object
Returns the value of attribute buf.
6 7 8 |
# File 'lib/net/http/spdy/stream.rb', line 6 def buf @buf end |
#connected ⇒ Object
Returns the value of attribute connected.
6 7 8 |
# File 'lib/net/http/spdy/stream.rb', line 6 def connected @connected end |
#eof ⇒ Object
Returns the value of attribute eof.
6 7 8 |
# File 'lib/net/http/spdy/stream.rb', line 6 def eof @eof end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/net/http/spdy/stream.rb', line 7 def id @id end |
#new_assoc ⇒ Object
Returns the value of attribute new_assoc.
6 7 8 |
# File 'lib/net/http/spdy/stream.rb', line 6 def new_assoc @new_assoc end |
#sock ⇒ Object (readonly)
Returns the value of attribute sock.
7 8 9 |
# File 'lib/net/http/spdy/stream.rb', line 7 def sock @sock end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/net/http/spdy/stream.rb', line 7 def uri @uri end |
Instance Method Details
#close_write ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/net/http/spdy/stream.rb', line 109 def close_write d = SPDY::Protocol::Data::Frame.new d.create(stream_id: @id, flags: 1) @session.monitor.synchronize do @sock.write d.to_binary_s end end |
#eof? ⇒ Boolean
22 23 24 |
# File 'lib/net/http/spdy/stream.rb', line 22 def eof? @buf.empty? && (@eof || @sock.eof?) end |
#read(len, dest = '', ignore_eof = false) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/net/http/spdy/stream.rb', line 26 def read(len, dest = '', ignore_eof = false) while @buf.size < len read_frame(ignore_eof) break if ignore_eof && eof? end dest << rbuf_consume(len) return dest end |
#read_all(dest = '') ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/net/http/spdy/stream.rb', line 35 def read_all(dest = '') dest << rbuf_consume(@buf.size) until eof? read_frame(false) dest << rbuf_consume(@buf.size) end return dest end |
#readline ⇒ Object
54 55 56 |
# File 'lib/net/http/spdy/stream.rb', line 54 def readline readuntil("\n").chop end |
#readuntil(terminator, ignore_eof = false) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/net/http/spdy/stream.rb', line 44 def readuntil(terminator, ignore_eof = false) idx = @buf.index(terminator) while idx.nil? read_frame(ignore_eof) idx = @buf.index(terminator) idx = @buf.size if ignore_eof && eof? end return rbuf_consume(idx + terminator.size) end |
#write(buf) ⇒ Object Also known as: <<
58 59 60 61 62 63 64 |
# File 'lib/net/http/spdy/stream.rb', line 58 def write(buf) d = SPDY::Protocol::Data::Frame.new d.create(stream_id: @id, data: buf) @session.monitor.synchronize do @sock.write d.to_binary_s end end |
#write_headers(method, path, ver, request) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/net/http/spdy/stream.rb', line 67 def write_headers(method, path, ver, request) h = { 'method' => method, 'url' => path, 'version' => "HTTP/#{ver}", 'scheme' => request.uri.scheme } h['host'] = request.delete("host").first %w(Connection Host Keep-Alive Proxy-Connection Transfer-Encoding).each do |i| raise ArgumentError, "Can't send #{i} with SPDY" if not request[i].nil? end sr = SPDY::Protocol::Control::SynStream.new(zlib_session: @session.parser.zlib_session) request.each_header do |key, value| h[key.downcase] = value end if request.request_body_permitted? sr.create(stream_id: @id, headers: h) else sr.create(stream_id: @id, headers: h, flags: 1) end @sock.debug_output.puts h if @sock.debug_output @session.monitor.synchronize do # wait to open a lower stream @session.monitor_cond.wait_while do @session.streams.detect{|s| s.id < @id && !s.connected } end @sock.write sr.to_binary_s @connected = true @session.monitor_cond.broadcast end end |
#write_protocol_error ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/net/http/spdy/stream.rb', line 101 def write_protocol_error d = SPDY::Protocol::Control::RstStream.new d.create(stream_id: @id, status_code: 1) @session.monitor.synchronize do @sock.write d.to_binary_s end end |