简体   繁体   English

http spec:等待创建“文件”

[英]http spec: Wait for creation of “file”

Is there a http related spec which helps me to implement "wait for creation of file"? 是否有与http相关的规范,可以帮助我实现“等待文件创建”?

Here is what should be implemented: 这是应该实现的:

  1. Server called "sink" connects to server "middle" and waits until a file on this server gets created 名为“接收器”的服务器连接到“中间”服务器,并等待直到在该服务器上创建文件
  2. Server "creator" creates a file and sends it to server "middle" 服务器“创建者”创建一个文件并将其发送到服务器“中间”
  3. As soon as the whole file is available at server "middle" server "sink" should start the download. 一旦整个文件在服务器“中间”可用,服务器“接收器”应立即开始下载。

I know that I could use websockets and custom methods to implement this. 我知道我可以使用websockets和自定义方法来实现这一点。

But before going this way I would like to know if there is a http related spec which does cover this use case. 但是在以这种方式进行操作之前,我想知道是否有涉及该用例的与http相关的规范。

Short answer 简短答案

Yes, the HTTP specification itself ( RFC7230 ) already covers your use case and there is also a known mechanism called HTTP Long Polling described in RFC6202 where a server waits for something for many seconds before returning a response. 是的,HTTP规范本身( RFC7230 )已经涵盖了您的用例,并且在RFC6202中还描述了一种称为HTTP Long Polling的已知机制,其中服务器在返回响应之前会等待几秒钟。

Long answer 长答案

HTTP is a flexible protocol, so much so that the HTTP specification itself ( RFC7230 ) already covers your use case. HTTP是一种灵活的协议,以至于HTTP规范本身( RFC7230 )已经涵盖了您的用例。 In Section 1 (emphasis mine): 第1节 (重点是我的)中:

HTTP is a generic interface protocol for information systems. HTTP是信息系统的通用接口协议。 It is designed to hide the details of how a service is implemented by presenting a uniform interface to clients that is independent of the types of resources provided . 它旨在通过向客户端提供与提供的资源类型无关的统一接口来隐藏服务实现方式的详细信息 Likewise, servers do not need to be aware of each client's purpose: an HTTP request can be considered in isolation rather than being associated with a specific type of client or a predetermined sequence of application steps. 同样,服务器不需要知道每个客户端的用途:可以将HTTP请求视为孤立的请求,而不是与特定类型的客户端或应用程序的预定顺序相关联。 The result is a protocol that can be used effectively in many different contexts and for which implementations can evolve independently over time. 结果是可以在许多不同的上下文中有效使用的协议,其实现可以随时间独立发展。

The specification allows the server to connect to other server and wait for something ("hide the details of how a service is implemented") and that something can be a file or anything else ("independent of the types of resources provided"). 该规范允许服务器连接到其他服务器并等待某些内容(“隐藏服务实现方式的详细信息”),并且某些内容可以是文件或其他任何内容(“与提供的资源类型无关”)。

You should notice that the specification does not define the internal workings of the server. 您应注意,该规范并未定义服务器的内部工作方式。 It does not define what the server must do in order to provide the response, as explained also in Section 1 (emphasis mine): 它没有定义服务器为提供响应所必须执行的操作,如第1节 (重点介绍)中所述:

One consequence of this flexibility is that the protocol cannot be defined in terms of what occurs behind the interface . 这种灵活性的结果是,不能根据接口后面发生事情来定义协议。

In your use case, server "sink" is actually a client because it connects to server "middle" expecting to receive a file. 在您的用例中,服务器“接收器”实际上是客户端,因为它连接到服务器“中间”并希望接收文件。 The fact that server "middle" is waiting for another server to do something is irrelevant because the specification does not define what should occur behind the interface. 服务器“中间”正在等待另一台服务器做某事的事实是无关紧要的,因为规范未定义接口后应该发生的事情。

However, if you are looking for a similar mechanism where the server also waits for something, one example would be HTTP Long Polling described in RFC6202 (emphasis mine): 但是,如果您正在寻找一种类似的机制,其中服务器还等待某些东西,那么一个示例就是RFC6202 (重点是我的)中描述的HTTP Long Polling:

HTTP Long Polling: The server attempts to "hold open" ( not immediately reply to ) each HTTP request, responding only when there are events to deliver. HTTP长轮询:服务器尝试“保持打开状态”( 不立即回复 )每个HTTP请求,仅在有要传递的事件时才响应。

In HTTP Long Polling, after receiving a client's request, the server does not reply immediately ("not immediately reply to"). 在HTTP Long Polling中,在接收到客户端的请求后,服务器不会立即答复(“未立即答复”)。 It simply waits for an event to occur. 它只是等待事件发生。 How long the server can wait is not even defined. 服务器可以等待多长时间甚至都没有定义。 This mechanism works within the confines of how HTTP works and therefore complies with HTTP specification. 该机制在HTTP工作方式的范围内起作用,因此符合HTTP规范。

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

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