Skip to content

Current CHUNKED implemantion in WebSever GitHub version not complete + HOW TO FIX #3225

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
horendus opened this issue May 10, 2017 · 3 comments

Comments

@horendus
Copy link

In testing the CHUNKED html send implementation in the current GitHub version I have found that it is not complete because it does not send a 0bytes body content message to the client to tell the browser to TERMINATE the chunked transfer session.

This causes the browser connection to remain active for an extra 2 seconds or so even though the entire HTML chunked transfer is complete This slows down the browser!

In looking at FireFox dev tools a chunked transfer of 5*3000byte HTML pieces is taking over 2300ms to complete with the later 2 seconds the browser is just sitting there waiting for its own transfer time out to kicks in.

After modifying the Webserver library I can have the transfer/transaction complete in just 150ms.

ADD to ESP8266WebSwerver.cpp

void ESP8266WebServer::endChunkedContent() {
	const char * end = "0\r\n\r\n";
	_currentClient.write(end, 5);
}

ADD to ESP8266WebServer.h
void endChunkedContent(); //Call this last when doing multiple server.sends (in CHUNKED trasnfers)

Then to do proper CHUNKED html transfers using the following method

  server.setContentLength(CONTENT_LENGTH_UNKNOWN);   //Enable Chunked Transfer
  server.send(200, "text/plain", webPagePart1());                      //Send first part WITH header
  server.sendContent(webPagePart2());                                    //Send next chunk of html
  server.sendContent(webPagePart3());                                    //Send next chunk of html
  server.endChunkedContent();                                               //Tell browser no more content is coming
@vortigont
Copy link

server.sendContent("");
server.client().stop()
can do the trick to send empty chunk and close the connection fast.

@igrr igrr added this to the 2.4.0 milestone May 23, 2017
@bryceschober
Copy link
Contributor

@igrr: Is the proposed fix not good enough, or are you planning on doing something different?

May i suggest an interface more like server.finish() that we could used to search-and-replace all the examples currently doing server.client().stop() with zero-length responses or content-length-unknown responses. It could properly terminate when chunking, and call server.client.stop() regardless, along the lines of:

void ESP8266WebServer::finish() {
  if(_chunked) {
    sendContent("");
  }
  _currentClient.stop();
}

@igrr
Copy link
Member

igrr commented Dec 14, 2017

@bryceschober If this issue is still relevant, could you please have a look at the proposed fix in #3963? It should be compatible with existing sketches which use chunked encoding, i think.

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

4 participants