Simple HTTP Server with one page index.html stored inside MBED as char vector and javascript to update a table content
Fork of HTTP_SERVER by
Diff: HTTP_SERVER.cpp
- Revision:
- 3:59884bc0a238
- Parent:
- 2:33714d7c0f45
- Child:
- 4:b551799053c6
diff -r 33714d7c0f45 -r 59884bc0a238 HTTP_SERVER.cpp --- a/HTTP_SERVER.cpp Sat Nov 26 18:06:53 2016 +0000 +++ b/HTTP_SERVER.cpp Sat Nov 26 18:22:42 2016 +0000 @@ -154,11 +154,11 @@ // Define behaviour of server according to Request Header lines // Apply request header field to response header field - char* field_Connection = NULL, - field_Upgrade = NULL, - field_Sec_WebSocket_Key = NULL, - field_Sec-WebSocket_Version = NULL, - field_Origin = NULL; + char* field_Connection = NULL; + char* field_Upgrade = NULL; + char* field_Sec_WebSocket_Key = NULL; + char* field_Sec_WebSocket_Version = NULL; + char* field_Origin = NULL; do { //Analyze the header feilds header_field_name = strtok(NULL, ":"); @@ -167,28 +167,18 @@ header_field_val++; if(header_field_name != NULL) { - switch(header_field_name) { - case "Connection": - filed_Connection = header_field_val; - break; - case "Upgrade": - field_Upgrade = header_field_val; - break; - case "Sec-WebSocket-Key": - field_Sec_WebSocket_Key = header_field_val; - break; - case "Sec-WebSocket-Version": - field_Sec_WebSocket_Version = header_field_val; - break; - case "Origin": - field_Origin = header_field_val; - break; - default: - break; + if(!strcmp(header_field_name, "Connection")) { + field_Connection = header_field_val; + } else if(!strcmp(header_field_name, "Upgrade")) { + field_Upgrade = header_field_val; + } else if(!strcmp(header_field_name, "Sec-WebSocket-Key") ) { + field_Sec_WebSocket_Key = header_field_val; + } else if(!strcmp(header_field_name, "Sec-WebSocket-Version") ) { + field_Sec_WebSocket_Version = header_field_val; + } else if(!strcmp(header_field_name, "Origin") ) { + field_Origin = header_field_val; } - } else { - break; - } + } else break; #ifdef DEBUG printf("(HTTP_SERVER) *header_field_name adr: %d %s\r\n", header_field_name - 1, header_field_name); printf("(HTTP_SERVER) header_field_val adr: %d %s\r\n", header_field_val - 1, header_field_val); @@ -196,7 +186,7 @@ } while(1); // if the request is to switching to the WebSocket Server - if( !strcmp(filed_Connection, "Upgrade") && + if( !strcmp(field_Connection, "Upgrade") && !strcmp(field_Upgrade, "websocket") && field_Sec_WebSocket_Key != NULL && !strcmp(field_Sec_WebSocket_Version, "13") && @@ -204,16 +194,18 @@ DEBUG_PRINT_LINE("(HTTP_SERVER) Communication Protocol will be Upgraded to Websocket! \r\n"); /* if(ws.isValid()){ + ...//calcurate the key msger.resetHeader(); msger.setStatusLine(101, "Switching Protocols"); if(msger.msger.setHeaderField("Connection", "Upgrade")) printf("(HTTP_SERVER)buffer over flow@ResposeMessenger"); if(msger.msger.setHeaderField("Upgrade", "websocket")) printf("(HTTP_SERVER)buffer over flow@ResposeMessenger"); if(msger.msger.setHeaderField("Sec-WebSocket-Accept", ...)) printf("(HTTP_SERVER)buffer over flow@ResposeMessenger"); if(msger.msger.setHeaderField("Access-Control-Allow-Origin", "*")) printf("(HTTP_SERVER)buffer over flow@ResposeMessenger"); - ... } + else goto AAA; */ } else { + //AAA: DEBUG_PRINT_LINE("(HTTP_SERVER) Communication Protocol won't be Upgraded.\r\n"); msger.setStatusLine(426, "Upgrade Required"); if(msger.setHeaderField("Connection", "Close"))printf("buffer over flow");