A simple web server that can be bound to either the EthernetInterface or the WiflyInterface.

Dependents:   Smart-WiFly-WebServer WattEye X10Svr SSDP_Server

Revision:
50:10db483f5154
Parent:
49:cd391662f254
Child:
51:758601b9bacd
--- a/SW_HTTPServer.cpp	Sun Apr 09 18:39:37 2017 +0000
+++ b/SW_HTTPServer.cpp	Mon Apr 10 20:58:52 2017 +0000
@@ -521,20 +521,29 @@
 {
     char http[100];
 
+    if (optional_text == NULL)
+        optional_text = "";
     INFO("header(%d, %s, %s, %s)", code, code_text, content_type);
     snprintf(http, sizeof(http), "%s %i %s\r\n", hdr_httpver, code, code_text);
     send(http);
     if (content_type) {
         send(content_type);
     }
-    if (optional_text) {
-        if (*optional_text != '\0')
-            send(optional_text);
+    if (*optional_text != '\0') {
+        send(optional_text);
     } else {
-        send(hdr_age);
-        send(hdr_server);
-        send(hdr_close);
-        header("");
+        if (strlen(hdr_age) + strlen(hdr_server) + strlen(hdr_close) + strlen(nl) < sizeof(http)) {
+            strcpy(http, hdr_age);
+            strcat(http, hdr_server);
+            strcat(http, hdr_close);
+            strcat(http, nl);
+            send(http);
+        } else {
+            send(hdr_age);
+            send(hdr_server);
+            send(hdr_close);
+            send(nl);
+        }
     }
 }