class H2::Server::Stream::PushPromise
Constants
- GET
- STATUS
Attributes
content_length[R]
path[R]
push_stream[R]
Public Class Methods
new(path:, headers: {})
click to toggle source
build a new PushPromise
for the path, with the headers and body given
# File lib/h2/server/stream/push_promise.rb, line 15 def initialize path:, headers: {}, body: nil @path = path @body = body @headers = headers @promise_headers = { METHOD_KEY => GET, AUTHORITY_KEY => headers.delete(AUTHORITY_KEY), PATH_KEY => @path, SCHEME_KEY => headers.delete(SCHEME_KEY) } @fsm = FSM.new end
Public Instance Methods
cancel!()
click to toggle source
cancel this promise, most likely due to a RST_STREAM frame from the client (already in cache, etc…)
# File lib/h2/server/stream/push_promise.rb, line 94 def cancel! @fsm.transition :canceled @stream.on_complete end
canceled?()
click to toggle source
# File lib/h2/server/stream/push_promise.rb, line 87 def canceled? @fsm.state == :canceled end
keep(size = nil) { || ... }
click to toggle source
deliver the body for this promise, optionally splicing into size
chunks
# File lib/h2/server/stream/push_promise.rb, line 57 def keep size = nil return false unless @fsm.state == :made if size.nil? @push_stream.data @body else body = @body if body.bytesize > size body = @body.dup while body.bytesize > size @push_stream.data body.slice!(0, size), end_stream: false yield if block_given? end else yield if block_given? end @push_stream.data body end @fsm.transition :kept log :info, self @stream.on_complete end
keep_async()
click to toggle source
# File lib/h2/server/stream/push_promise.rb, line 51 def keep_async @stream.connection.server.async.handle_push_promise self end
kept?()
click to toggle source
# File lib/h2/server/stream/push_promise.rb, line 83 def kept? @fsm.state == :kept end
log(level, msg)
click to toggle source
# File lib/h2/server/stream/push_promise.rb, line 99 def log level, msg Logger.__send__ level, "[stream #{@push_stream.id}] #{msg}" end
make_on(stream)
click to toggle source
create a new promise stream from stream
, send the headers and set +@push_stream+ from the callback
# File lib/h2/server/stream/push_promise.rb, line 33 def make_on stream return unless @fsm.state == :init @stream = stream @headers = {STATUS_KEY => STATUS}.merge stringify_headers(@headers) check_accept_encoding @content_length = @body.bytesize.to_s @headers.merge! CONTENT_LENGTH_KEY => @content_length @stream.stream.promise(@promise_headers, end_headers: false) do |push| push.headers @headers @push_stream = push @push_stream.on(:close){|err| cancel! if err == :cancel} end @fsm.transition :made self end
to_s()
click to toggle source
# File lib/h2/server/stream/push_promise.rb, line 103 def to_s request = @stream.request %{#{request.addr} "push #{@path} HTTP/2" #{STATUS} #{@content_length}} end
Also aliased as: to_str