What to do with errors when streaming the body of an Http request

One of the following should do it:

  1. Close the connection (reset or normal close)
  2. Write a malformed chunk (and close the connection) which will trigger client error
  3. Add a http trailer telling your client that something went wrong.
  4. Change your higher level protocol. Last piece of data you send is a hash or a length and the client knows to deal with it.
  5. If you can generate a hash or a length (in a custom header if using http chunks) of your content before you start sending you can send it in a header so your client knows what to expect.

It depends on what you want your client to do with the data (keep it or throw it away). You may not be able to make changes on the client side so the last option will not work for example.

Here is some explanation about the different ways to close. TCP option SO_LINGER (zero) – when it’s required.

Leave a Comment