gpt4 book ai didi

ruby - 如何使用 Typhoeus 在 on_body 回调中中止当前请求

转载 作者:数据小太阳 更新时间:2023-10-29 08:47:29 27 4
gpt4 key购买 nike

我正在使用 Typhoeus 和一个包含十几个请求的 hydra 队列。

我正在使用 on_body 回调来流式传输响应。

当然,在不中止队列中所有其他请求的情况下,在此回调中中止当前请求(即达到最大文件大小...)的最佳方法是什么?

hydra = Typhoeus::Hydra.hydra

urls.each do |url|
request = Typhoeus::Request.new(url, followlocation: true, timeout: 5, connecttimeout: 5)
request.on_body do |chunk, response|
#
# How to conditionally abort the request here ?
#
end

hydra.queue request
end

hydra.run

最佳答案

暂时没有办法。根据http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTWRITEFUNCTION返回无效大小就足够了。但这在 Typhoeus 中还不是一个选项,因为回调本身被包装并且它总是返回正确的大小:https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/callbacks.rb#L37-48 .

编辑:Ethon 0.7.1 能够在 on_body 回调中中止请求:https://github.com/typhoeus/ethon/commit/6117872004c9ed1dac0ac15542dffc10177d8eae .

关于ruby - 如何使用 Typhoeus 在 on_body 回调中中止当前请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23383959/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com