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: PPP-Blinky/ppp-blinky.cpp
- Revision:
- 185:4cd8f91e9d49
- Parent:
- 184:4133f557d4d4
- Child:
- 193:8d3c9e94a4fb
--- a/PPP-Blinky/ppp-blinky.cpp Mon Sep 11 23:33:27 2017 +0000 +++ b/PPP-Blinky/ppp-blinky.cpp Mon Sep 18 16:35:49 2017 +0000 @@ -869,7 +869,7 @@ #define TCP_FLAG_FIN (1<<0) /// respond to an HTTP request -int httpResponse(char * dataStart) +int httpResponse(char * dataStart, int * flags) { int n=0; // number of bytes we have printed so far n = webSocketHandler( dataStart ); // test for and handle WebSocket upgrade requests @@ -878,6 +878,7 @@ int nHeader; // byte size of HTTP header int contentLengthStart; // index where HTML starts int httpGet5,httpGet6,httpGetx, httpGetRoot; // temporary storage of strncmp results + *flags = TCP_FLAG_ACK | TCP_FLAG_FIN; // the default case is that we close the connection httpGetRoot = strncmp(dataStart, "GET / HTTP/1.", 13); // found a GET to the root directory httpGetx = strncmp(dataStart, "GET /x", 6); // found a GET to /x which we will treat special (anything starting with /x, e.g. /x, /xyz, /xABC?pqr=123 @@ -895,16 +896,18 @@ n=n+sprintf(n+dataStart,"Connection: close\r\n"); // close connection immediately n=n+sprintf(n+dataStart,"Content-Type: text/html; charset=us-ascii\r\n\r\n"); // http header must end with empty line (\r\n) nHeader=n; // size of HTTP header + if( httpGetRoot == 0 ) { // this is where we insert our web page into the buffer memcpy(n+dataStart,rootWebPage,sizeof(rootWebPage)); n = n + sizeof(rootWebPage)-1; // one less than sizeof because we don't count the null byte at the end + } else if ( (httpGet5 == 'w') && (httpGet6 == 's') ) { // "ws" is a special page for websocket demo memcpy(n+dataStart,webSocketPage,sizeof(webSocketPage)); n = n + sizeof(webSocketPage)-1; // one less than size + *flags = TCP_FLAG_ACK | TCP_FLAG_PSH; // for a websocket page we do NOT close the connection } else { if (httpGetx == 0) { // the page request started with "GET /x" - here we treat anything starting with /x special: - #define W3C_COMPLIANT_RESPONSE_NO // change the above to W3C_COMPLIANT_RESPONSE_YES if you want a W3C.org compliant HTTP response #ifdef W3C_COMPLIANT_RESPONSE_YES @@ -1017,7 +1020,7 @@ int dataLen = 0; // most of our responses will have zero TCP data, only a header int flagsOut = TCP_FLAG_ACK; // the default case is an ACK packet - ppp.tcp->windowR = __REV16( 1200 ); // set tcp window size to 120 bytes + ppp.tcp->windowR = __REV16( 1200 ); // set tcp window size to 1200 bytes // A sparse TCP flag interpreter that implements stateless TCP connections @@ -1032,7 +1035,7 @@ if ( (ppp.tcp->flag.All == TCP_FLAG_ACK) && (tcpDataSize == 0)) return; // handle zero-size ack messages by ignoring them if ( (strncmp(tcpDataIn, "GET /", 5) == 0) ) { // check for an http GET command flagsOut = TCP_FLAG_ACK | TCP_FLAG_PSH; // we have data, set the PSH flag - dataLen = httpResponse(tcpDataOut); // send an http response + dataLen = httpResponse(tcpDataOut, &flagsOut); // send an http response } else { dataLen = tcpResponse(tcpDataOut,tcpDataSize, &flagsOut); // not an http GET, handle as a tcp connection if (dataLen > 0) flagsOut = TCP_FLAG_ACK | TCP_FLAG_PSH; // if we have any data set the PSH flag