mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
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:
parent
10146be1bc
commit
3ffbed8a30
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user