Skip to content

SDWebServer printDirectory CONTENT_LENGTH_UNKNOWN doesn't send last-chunk #2481

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

Closed
JamesNewton opened this issue Sep 4, 2016 · 2 comments · Fixed by #6808
Closed

SDWebServer printDirectory CONTENT_LENGTH_UNKNOWN doesn't send last-chunk #2481

JamesNewton opened this issue Sep 4, 2016 · 2 comments · Fixed by #6808

Comments

@JamesNewton
Copy link

Description

In the sample code, in the printDirectory routine, which is one of the only examples I can find where anyone uses
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
what closes the connection after the listing is returned?

Shouldn't there be a server.sendContent(""") at the end of the procedure?

When chunking is used, and no Content-Length is supplied in the Header of an HTTP 1.1 response, the last chunk is supposed to have zero length...
http://greenbytes.de/tech/webdav/rfc2616.html#rfc.section.3.6.1
http://greenbytes.de/tech/webdav/rfc2616.html#introduction.of.transfer-encoding

Hardware

Hardware: ESP-12

Settings in IDE

Module: Generic ESP8266 Module
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: DIO
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: nodemcu... actually manual.

Sketch

/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino

Debug Messages

None... dang it... I don't know how to spy on the HTTP data.

What bothers me most is that the code appears to work... and I can't figure out why... Are modern browsers just closing the connection after a while? Nothing in the spec about that which I can find...

@bbx10
Copy link
Contributor

bbx10 commented Jul 24, 2017

@JamesNewton I confirmed the same problem. Chromium gets stuck waiting for more data without the 0 length chunk. For example, http://<ESP IP addr>/list?dir=/ works correctly only after the 0 length chunk is added. This bug affects edit mode as well. The left side panel is supposed to show the filenames but is blank without this fix. I suggest submitting a PR. I will fix the ESP32 version.

@devyte
Copy link
Collaborator

devyte commented Oct 13, 2017

The example still doesn't have the empty chunk in latest git.

@earlephilhower earlephilhower self-assigned this Nov 19, 2019
earlephilhower added a commit to earlephilhower/Arduino that referenced this issue Nov 19, 2019
Fixes esp8266#2481

Send a 0-len chunk when the directory is completed (in a chunked HTTP
transfer) to terminate the HTTP transfer properly.
@devyte devyte added this to the 2.6.2 milestone Nov 19, 2019
d-a-v pushed a commit that referenced this issue Nov 19, 2019
Fixes #2481

Send a 0-len chunk when the directory is completed (in a chunked HTTP
transfer) to terminate the HTTP transfer properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants