简体   繁体   English

http是否可以发送流式响应而不是“ Range”响应/请求?

[英]Can http send a streamed response without it being a “Range” response/request?

Can an http server respond with data bit by bit - without it being in response to a "Range" request? http服务器能否在不响应“范围”请求的情况下一点一点地响应数据?

For example, say I want to continually stream text data back to a client - an almost never ending http stream of textual data, which is received by the client as the result of a single http request. 例如,假设我要持续将文本数据流传输回客户端-文本数据的HTTP几乎永无止境的流,由于单个http请求的结果,客户端接收到该文本流。

Can I do this without the client sending me a "Range" request in response to me sending an "Accept-Ranges" header? 我可以在没有客户端发送“ Range”请求来响应我发送“ Accept-Ranges”标头的情况下执行此操作吗?

And I do see code examples of servers streaming data back to clients , but are those clients expected to have sent a range header? 我确实看到了服务器将数据流传输回客户端的代码示例 ,但是这些客户端是否应该发送了范围标头?

A range request asks for a specific range of bytes for a resource. 范围请求要求资源的特定字节范围。 It's safe to expect that the request ends in a reasonable time. 可以肯定的是,请求会在合理的时间内结束。 However nothing stops you from pushing data from the server without closing/ending the connection in a regular request. 但是,没有什么可以阻止您从服务器中推送数据而无需在常规请求中关闭/结束连接。 It just means the request will take a long time and possibly waste resources on the server. 这仅意味着请求将花费很长时间,并且可能浪费服务器上的资源。

This is sometimes called "long polling", especially when the connection is idle (but still alive) for most of the time, sending data only when something happens on the server. 有时这称为“长时间轮询”,尤其是在大多数情况下连接处于空闲状态(但仍处于活动状态)时,仅当服务器上发生某些情况时才发送数据。 An example would be a web based chat, although websockets would be more suitable than HTTP in these modern times. 一个示例是基于Web的聊天,尽管在当今时代Websocket比HTTP更合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM