HTTP Response before Request

后端 未结 7 1868
梦毁少年i
梦毁少年i 2020-12-23 17:16

My question might sound stupid, but I just wanted to be sure:

  • Is it possible to send an HTTP response before having the request for that resource?
7条回答
  •  抹茶落季
    2020-12-23 17:42

    If someone requests /index.html and you send two responses (one for /index.html and the other for /img.jpg), how do you know the recipient will get the two responses and know what to do with them before the second request goes in?

    The problem is not really with the sending. The problem is with the receiver possibly getting unexpected data.

    One other issue is that you're denying the client the ability to use HTTP caching tools like If-Modified-Since and If-None-Match (i.e. the client might not want /img.jpg to be sent because it already has a cached copy).

    That said, you can approximate the server-push benefits by using Comet techniques. But that is much more involved than simply anticipating incoming HTTP requests.

提交回复
热议问题