[Solved] Chunked file transfer
Added by laszlo.gyimothy over 6 years ago
Hi All,
I would like to implement in C, chunked file transfer using the Lighttpd. My server consists of two EXE file, the Lighttpd.exe and the BusinessLogic.exe. They communicate using the FastCGI.
My use case is the following:
1. the client sends a GET request to the server
2. the server starts to generate the response file and sends it back to the client in chunked mode
My solution is the following:
1. if the business logic gets the request, it creates the response header in string format: "... transfer encodig: chuncked ... " and sends it via FastCGI to the Lighttpd: "(void)FCGX_FPrintF(p_response->p_fcgi->out, "%s: %s\r\n", p_element, p_value);"
2. if the header is ready, the business logic generates the data and send them to the Lighttpd: "n_write = FCGX_PutStr((const char *)p_send_buf, (int)len_send_buf, p_response->p_fcgi->out);"
I did a Wireshark trace of the network traffic and I cannot see the chunked mode specific \r\n, line separators at the end of the data chunkes.
What could be the problem, do I have to set the Lighttpd to chunked mode somehow before I start to send the response? Or could you please send me an example?
Thank you for your help!
Laszlo
Replies (5)
RE: Chunked file transfer - Added by gstrauss over 6 years ago
Don't send chunked encoding from FastCGI. Simply send just the business logic response from your FastCGI program.
Configure lighttpd to stream the response and lighttpd will send Transfer-Encoding: chunked if supported by the client (HTTP/1.1)
See server.stream-response-body
RE: Chunked file transfer - Added by laszlo.gyimothy over 6 years ago
Thank you very much for your quick answer!
RE: Chunked file transfer - Added by laszlo.gyimothy over 6 years ago
An additionaly question: "server.stream-response-body" is a global configuration for the server, am I right? Is it possible to set the streaming only for a given connection? I mean if the client wants to download a given file, then use this setting only for this given URI.
RE: [Solved] Chunked file transfer - Added by gstrauss over 6 years ago
An additionaly question: "server.stream-response-body" is a global configuration for the server, am I right?
No, you're not right. Would it have been so hard to test this yourself so that you could have answered the question for yourself? Try putting the directive inside a condition for the URL-path you would like to stream.
RE: [Solved] Chunked file transfer - Added by laszlo.gyimothy over 6 years ago
This was not clear for me :( but thank you for your help!