push promise stream callback is now as upper-level as it can get; this allows it to be redefined better

This commit is contained in:
HoneyryderChuck 2018-01-13 17:52:55 +00:00
parent 10146be1bc
commit 3ffbed8a30
2 changed files with 17 additions and 5 deletions

View File

@ -202,9 +202,7 @@ module HTTPX
end
def on_promise(stream)
log(2, "#{stream.id}: ") { "refusing stream!" }
stream.refuse
# TODO: policy for handling promises
emit(:promise, stream)
end
def method_missing(meth, *args, &blk)

View File

@ -39,6 +39,12 @@ module HTTPX
@responses[request] = response
end
def on_promise(stream)
log(2, "#{stream.id}: ") { "refusing stream!" }
stream.refuse
# TODO: policy for handling promises
end
def fetch_response(request)
response = @responses.delete(request)
if response.is_a?(ErrorResponse) && response.retryable?
@ -51,8 +57,16 @@ module HTTPX
def find_channel(request)
uri = URI(request.uri)
@connection.find_channel(uri) ||
@connection.build_channel(uri, &method(:on_response))
@connection.find_channel(uri) || begin
channel = @connection.build_channel(uri)
set_channel_callbacks(channel)
channel
end
end
def set_channel_callbacks(channel)
channel.on(:response, &method(:on_response))
channel.on(:promise, &method(:on_promise))
end
def __build_reqs(*args, **options)