Storing HTTP data across multiple packets?

What is the correct way for an HTTP server to send data across multiple packets?

For example, I want to transfer a file, the first package I send:

HTTP/1.1 200 OK Content-type: application/force-download Content-Type: application/download Content-Type: application/octet-stream Content-Description: File Transfer Content-disposition: attachment; filename=test.dat Content-Transfer-Encoding: chunked 400 <first 1024 bytes here> 400 <next 1024 bytes here> 400 <next 1024 bytes here> 

Now I need to create a new package if I just send:

 400 <next 1024 bytes here> 

All clients that close my connections and files are truncated.

What headers do I put in the second packet to continue the flow of data?

+7
packet chunked-encoding
source share
5 answers

My lack of reputation does not allow me to comment on the question, just answer it, so I assume that something like โ€œyou are trying to implement HTTP 1.1 on the web server of an embedded device that has a packet network stack instead of stream-orientedโ€ is true, or you will not talk about packages. (If you are talking about pieces, see Other Answers.)

Given that - use sockets if you can; you do not need to think in packages. There probably is a wrapper for your network stack. If this does not happen, write a file that does not harm your execution too much.

If you cannot for any reason - you are likely to blow out the size of the first packet. Your MTU is probably something like 1500 or 1492 (or less), and you have + 5 + 1024 + 5 + 1024 + 5 + 1024 bytes listed "in your first packet." Your network stack may suck enough so that it does not give you error codes, or your code may not check them - or it may do something else equally useless.

+3
source

There is no concept of packets in HTTP. Your HTTP stream can even be split into 1 byte packets.

For encoded encoding, you must specify the necessary headers for each fragment (which is not related to packets), as indicated in the RFC.

+3
source

First, the right title

 Transfer-Encoding: chunked 

not Content-Transfer-Encoding .

Also, why are you sending three different Content-Type headers?

+2
source

Typically, you should use Accept-Ranges and Content-Range on the server side to notify the client that the server is accepting a resume. The client will then send the Range header to request a partial download.

Since the Content-Range header requires a full file length, and this is not known here (otherwise there was no reason to choose chunked for encoding), you are lost in relation to the standard HTTP specification code. You will either choose another protocol or your own specification, or look at alternative ways to find the length of the content anyway.


However, the three Content-Type headers make no sense. Choose one. Content-Transfer-Encoding also incorrect, it must be Transfer-Encoding .

+2
source

All Articles