Skip to content

stop client #7

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

Open
aiotech-pub opened this issue Jan 3, 2022 · 1 comment
Open

stop client #7

aiotech-pub opened this issue Jan 3, 2022 · 1 comment

Comments

@aiotech-pub
Copy link

I am porting an application from ESPWebServer to ESPWebServerSecure.
To send back to the client the content of a HTML page I just need to fill the String webpage and call these 5 functions:

static void append_page_header() 
{
   #define SITE_WIDTH 1020
   #define version "1.0"
   webpage  = F("<!DOCTYPE HTML><html lang='en'><head>");
   webpage += "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>";
   webpage += F("<title>Invio di messaggi - Talking Tree</title><style>");
   webpage += F("body {width:");
   webpage += SITE_WIDTH;
   webpage += F("px;margin:0 auto;font-family:arial;font-size:14px;text-align:center;color:#776688;background-color:#F7F2Fd;}");
   webpage += F("ul{list-style-type:circle; margin:0;padding:0;overflow:hidden;background-color:#d8d8d8;font-size:14px;}");
   webpage += F("li{float:left;border-right:1px solid #bbb;}last-child {border-right:none;}");
   webpage += F("li a{display: block;padding:2px 12px;text-decoration:none;}");
   webpage += F("li a:hover{background-color:#FFFFFF;}");
   webpage += F("section {font-size:16px;}");
   webpage += F("p {background-color:#D1DBE3;font-size:16px;}");
   webpage += F("div.header,div.footer{padding:0.5em;color:white;background-color:gray;clear:left;}");
   webpage += F("h1{background-color:#d8d8d8;font-size:26px;}");
   webpage += F("h2{color:#9370DB;font-size:22px;line-height:65%;}");
   webpage += F("h3{color:#9370DB;font-size:16px;line-height:55%;}");
   webpage += F("</style></head><body><h1>Talking Tree ");
   webpage += String(version)+"</h1>";
}
//---------------------------------------------------------------------------

static void append_page_footer()
{ 
   webpage += F("<ul><li><a href='/'>Page reload</a></li></ul>");
   webpage += F("</body></html>");
}
//---------------------------------------------------------------------------

static void SendHTML_Header()
{
  server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); 
  server.sendHeader("Pragma", "no-cache"); 
  server.sendHeader("Expires", "-1"); 
  server.setContentLength(CONTENT_LENGTH_UNKNOWN); 
  server.send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. 
  append_page_header();
  server.sendContent(webpage);
  webpage = "";
}
//-----------------------------------------------------------------------------

static void SendHTML_Content()
{
  server.sendContent(webpage);
  webpage = "";
}
//-----------------------------------------------------------------------------

static void SendHTML_Stop()
{
  server.sendContent("");
  server.client().stop(); // Stop is needed because no content length was sent
}
//-----------------------------------------------------------------------------

this is an example:

static void ReportCouldNotCreateFile(String target)
{
  SendHTML_Header();
  webpage += F("<h3>Could Not Create Uploaded File (write-protected?)</h3>"); 
  webpage += F("<a href='/"); webpage += target + "'>[Back]</a><br><br>";
  append_page_footer();
  SendHTML_Content();
  SendHTML_Stop();
}
//-----------------------------------------------------------------------------

so I would like to modify as little as possible these functions... the only problem is in the last line of SendHTML_Stop():
server.client().stop(); // Stop is needed because no content length was sent because there is no reference to the connected client.

Is there an equivalent way to obtain the same result?
Thanks.

@bwjohns4
Copy link

bwjohns4 commented May 7, 2022

@aiotech-pub, did you ever figure out a workaround for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants