-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content-Type header set to default when chunking static files #206
Comments
What are the ones you tried ? |
I have a configuration web page that I have to serve over ethernet or WiFi and connecting to the ESP hotspot. I've tried different forks of ESPAsyncWebServer, using both AsyncTCP and AsyncTCPSock with very poor performance (I'm getting out of RAM and most of the times the browser didn't get the required files). The second best option I was using is your fork mathieucarbou/ESPAsyncWebServer @ 3.6.0, serving manually the files and chunking the responses if the file was big enough (>20K). But even with this I'm getting out of RAM pretty quickly and it gets worse over the time (maybe some memory is not freed correctly in some cases). I also tried to build a queue of requests and serve the files in a different task with no luck (how to do this properly, probably exceeds my knowledge). For the moment PsychicHttp is the best in terms of RAM usage and I can see that is closing the connections when not needed. Thank you for the hard work on both projects. |
Ok! Probably a usage issue in the app then. ESPAsyncWS is capable of serving huge files concurrently or big files from sdcard or flash with only using a minimal heap. There are examples of that in the project. In any case, if you want, you can open a ticket in the discussion tab to show your use case and what was not correctly working. It might be possible you were not using the right endpoint to do what you wanted. Some endpoints are doing string copy in a buffer because the data would become out of scope from caller side. Some endpoints are using references to avoid allocating.
yeah, like both ;-) About your request, you can look at how sendHeaders(); is called first, then a sendChunk() in a loop. sendChunk() is just sending by batches the bytes to the browser. HTTP headers are sent first, so no need to reset them again they won't be sent. |
That makes sense, I will take a closer look a that thanks for the clue :)
I see how it's implemented, and all the headers are sent correctly, except for the Content-Type when the response is chunked. I'll try to explain it more clearly, as I believe there is some missing code. Take a look at the arrows in the code (<--------) for reference. 1. File not chunkedWe send the file with
2. Chunked fileIn this case we send the headers and then loop with sendChunk()
If you look at
I believe we need to set the Content Type using
|
yes indeed... would you mind sending a PR ? Your solution makes sense I think and is also as per the doc. I will merge your PR after. Note: you are using v2 right ? |
Sorry, I've been busy these days. I just sent the PR setting the status too.
yes |
When serving small files (less than chunk size) the content-type header is passed to the browser. However, for large files it is set to default (text/html). I added the following line to make it work, but I'm not sure if it is the best way to do it.
Thank you, this is finally a good async server that does not hang the ESP32 :)
The text was updated successfully, but these errors were encountered: