Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of webserverBlinky by
Diff: main.cpp
- Revision:
- 32:512228c29209
- Parent:
- 31:e000c1b9c565
- Child:
- 33:b5a86ff03f3d
--- a/main.cpp Thu Jan 05 02:16:53 2017 +0000 +++ b/main.cpp Thu Jan 05 02:59:17 2017 +0000 @@ -545,13 +545,13 @@ // let's check incoming text for an HTTP home page GET request if ( strncmp(dataStart, "GET / HTTP/1.1", 14) == 0) { - flagbitstcp[1] = TCP_FLAG_FIN; // close connection after delivering page + flagbitstcp[1] = TCP_FLAG_ACK | TCP_FLAG_FIN; // close connection after delivering page dataLen = 15*32; // this block has to hold the web page below, but keep it under 1k memset(dataStart,'x', dataLen ); // initialize the block int n=0; // number of bytes we have printed so far n=n+sprintf(n+dataStart,"HTTP/1.1 200 OK\r\nServer: PPP-Blinky\r\n"); // http header n=n+sprintf(n+dataStart,"Content-Length: 378\r\n"); // http header - n=n+sprintf(n+dataStart,"Content-Type: text/html;charset=us-ascii\r\n\r\n"); // http header + n=n+sprintf(n+dataStart,"Content-Type: text/html; charset=us-ascii\r\n\r\n"); // http header int nHeader=n; // byte total of all headers n=n+sprintf(n+dataStart,"<html><head><title>mbed-PPP-Blinky</title><script>window.onload=function()"); // html n=n+sprintf(n+dataStart,"{setInterval(function(){function x(){return document.getElementById('w');};"); // html @@ -564,13 +564,20 @@ debug(("HTTP GET dataLen %d*32=%d Header %d Content-Length %d Total %d Margin %d\n",dataLen/32,dataLen,nHeader,contentLength,n,dataLen-n-1)); } } else if ( strncmp(dataStart, "GET /", 4) == 0) { - flagbitstcp[1] = TCP_FLAG_FIN; // close connection after delivering page - dataLen = 2*32; // this block has to hold the web page below, but keep it under 1k + flagbitstcp[1] = TCP_FLAG_ACK | TCP_FLAG_FIN; // close connection after delivering page + dataLen = 5*32; // this block has to hold the web page below, but keep it under 1k memset(dataStart,'x', dataLen ); // initialize the block - int n=0; // number of bytes we have printed so far - n=n+sprintf(n+dataStart,"HTTP/1.1 404 Not Found\r\n\r\n\r\n\r\n"); // http header + int n=0; + n=n+sprintf(n+dataStart,"HTTP/1.1 200 OK\r\nServer: PPP-Blinky\r\n"); // http header + n=n+sprintf(n+dataStart,"Content-Length: 58\r\n"); // http header + n=n+sprintf(n+dataStart,"Content-Type: text/html; charset=us-ascii\r\n\r\n"); // http header + int nHeader=n; // byte total of all headers + n=n+sprintf(n+dataStart,"<html><head>"); // html + n=n+sprintf(n+dataStart,"<body><h1>File Not Found</h1></body>\r\n</html>"); // html + int contentLength = dataLen-nHeader; // this is how to calculate Content-Length, but using curl -v is easier + contentLength = contentLength+0; // get around unreferenced variable warning if (v0) { - debug(("HTTP 404 Not Found\n")); + debug(("HTTP GET dataLen %d*32=%d Header %d Content-Length %d Total %d Margin %d\n",dataLen/32,dataLen,nHeader,contentLength,n,dataLen-n-1)); } } }