Sha256: 3f2a6afbe3ebac56a18d9cbcbf35f17d23380851315613a1236ea7fe820fa262
Contents?: true
Size: 1.94 KB
Versions: 3
Compression:
Stored size: 1.94 KB
Contents
# frozen_string_literal: true module HTTPX module Plugins module PushPromise PUSH_OPTIONS = { http2_settings: { settings_enable_push: 1 }, max_concurrent_requests: 1 }.freeze module ResponseMethods def pushed? @__pushed end def mark_as_pushed! @__pushed = true end end module InstanceMethods def initialize(opts = {}) super(PUSH_OPTIONS.merge(opts)) @promise_headers = {} end private def on_promise(parser, stream) stream.on(:promise_headers) do |h| __on_promise_request(parser, stream, h) end stream.on(:headers) do |h| __on_promise_response(parser, stream, h) end end def __on_promise_request(parser, stream, h) log(1, "#{stream.id}: ") do h.map { |k, v| "-> PROMISE HEADER: #{k}: #{v}" }.join("\n") end headers = @options.headers_class.new(h) path = headers[":path"] authority = headers[":authority"] request = parser.pending.find { |r| r.authority == authority && r.path == path } if request request.merge_headers(headers) @promise_headers[stream] = request parser.pending.delete(request) else stream.refuse end end def __on_promise_response(parser, stream, h) request = @promise_headers.delete(stream) return unless request parser.__send__(:on_stream_headers, stream, request, h) request.transition(:done) response = request.response response.mark_as_pushed! stream.on(:data, &parser.method(:on_stream_data).curry[stream, request]) stream.on(:close, &parser.method(:on_stream_close).curry[stream, request]) end end end register_plugin(:push_promise, PushPromise) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
httpx-0.0.3 | lib/httpx/plugins/push_promise.rb |
httpx-0.0.2 | lib/httpx/plugins/push_promise.rb |
httpx-0.0.1 | lib/httpx/plugins/push_promise.rb |