Skip to content

CaptivePortalAdvanced example doesn't call setContentLength #1718

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
krebbi opened this issue Mar 3, 2016 · 4 comments
Closed

CaptivePortalAdvanced example doesn't call setContentLength #1718

krebbi opened this issue Mar 3, 2016 · 4 comments

Comments

@krebbi
Copy link

krebbi commented Mar 3, 2016

Basic Infos

Hardware

Hardware: ESP-12E
Core Version: 2.1.0

Description

this returns an empty response since 2.1.0:

ESP8266WebServer webServer(80);
webServer.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
webServer.sendHeader("Pragma", "no-cache");
webServer.sendHeader("Expires", "-1");
webServer.send(200, "text/html", "");
webServer.sendContent(
""
""
"

My HTML

"
""
);
webServer.client().stop();

but this works:

ESP8266WebServer webServer(80);
webServer.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
webServer.sendHeader("Pragma", "no-cache");
webServer.sendHeader("Expires", "-1");
webServer.send(200, "text/html", "

My HTML

");

Settings in IDE

Module: NodeMCU 1.0
Flash Size: 4MB/
CPU Frequency: 80Mhz
Flash Mode: ?
Flash Frequency: ?
Upload Using: SERIAL
Reset Method: ?

Sketch

see above

@igrr
Copy link
Member

igrr commented Mar 3, 2016

If you intend to send more than once, you need to supply content length or let WebServer know that it is undefined. So before calling send the first time, call server.setContentLength( length ); or server.setContentSize(CONTENT_LENGTH_UNKNOWN) if you don't know it upfront. I wouldn't recommend using CONTENT_LENGTH_UNKNOWN because in this case there will be good chance that server has to close TCP connection actively, which is bad for heap usage. Better calculate the content length and pass it to the server, so that the client knows when the all data is received.

@krebbi
Copy link
Author

krebbi commented Mar 3, 2016

which version you are working with?
I get
'class ESP8266WebServer' has no member named 'setContentSize'
when trying your approach

@igrr
Copy link
Member

igrr commented Mar 3, 2016

Sorry, that was a typo — the function is called setContentLength: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WebServer/src/ESP8266WebServer.h#L114

I'm using the latest git version, but the function should be present both in latest stable (2.1.0) and staging (2.1.0-rc2).

@krebbi
Copy link
Author

krebbi commented Mar 3, 2016

that works, thx!

maybe you should update the CaptivePortalAdvanced Example accordingly.

@igrr igrr changed the title Webserver returns empty response Update CaptivePortalAdvanced example to call setContentLength Mar 3, 2016
@igrr igrr changed the title Update CaptivePortalAdvanced example to call setContentLength CaptivePortalAdvanced example doesn't call setContentLength Mar 3, 2016
@igrr igrr added this to the 2.2.0 milestone Mar 3, 2016
igrr referenced this issue Mar 21, 2016
This is needed since when the content-length header is not sent the clients will
wait for data anyways. Sending a content length of zero will tell the client not
to expect any content and it will close the connection immediately.
@igrr igrr closed this as completed in ed13edf Mar 23, 2016
igrr added a commit that referenced this issue Mar 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants