在 Haskell 中寻找一个允许将 Web 响应主体作为流使用的包

发布于 2024-09-06 01:13:37 字数 1539 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我偏爱纯白色 2024-09-13 01:13:37

您想要客户端以流的形式下载文件吗? 怎么样download-curl 的惰性接口

可能适合您的需求(或稍作调整)。

You want client-side downloading of files as a stream? How about download-curl's lazy interface?

Might be fine for your needs (or with a little tweaking).

雨夜星沙 2024-09-13 01:13:37

一般来说,存在与延迟解析某些内容和验证相关的常见问题。当您收到包含“Content-Length”标头的 HTTP 响应时,您必须检查在连接关闭之前是否会读取所有数据。这意味着您不能说该响应有效,直到您读到最后。您的映射必须等待,然后处理整个结果。
为了避免您的库可能不那么严格,只检查标头的正确性和可能的​​数据的第一部分(如果分块或压缩)并返回长度小于或等于“Content-Length”的主体。或者您可以使用自己的块流,它返回成功或失败作为最后一个块。
另一种方法是在读取数据时牺牲 CPU 来处理响应(例如在 monad 内部),并且当下次读取没有有效数据时,您将中止之前的所有计算。

我建议也看看 http-monad 。从未使用过它,但我希望通过 monad 接口它可以实现最后一种方法。

In general there is common problem related with parsing something lazily with validation. When you receives HTTP response which contains "Content-Length" header you have to check that you'll read all that data before connection will be closed. That means that you can't say that response is valid until you'll read till the very end. And your mapping will have to wait and then process the whole result.
To avoid that your library may be less strict and check only header correctness and probably first part of data (in case chunked or compressed) and return body with length less or equal to "Content-Length". Or you may use your own chunk-stream which returns Success or Fail as the last chunk.
Another approach is to sacrifice your CPU for processing response as you read it (ex. inside monad) and when there is no valid data for next read you abort all your previous calculation.

I'd suggest to look at http-monad also. Never used it, but I hope that with monad interface it implements that last approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文