Browse Source

Setting content-length

Sergey Lyubka 13 years ago
parent
commit
ef4bd8f758
1 changed files with 11 additions and 5 deletions
  1. 11 5
      examples/hello.c

+ 11 - 5
examples/hello.c

@@ -6,11 +6,17 @@ static void *callback(enum mg_event event,
                       struct mg_connection *conn,
                       struct mg_connection *conn,
                       const struct mg_request_info *request_info) {
                       const struct mg_request_info *request_info) {
   if (event == MG_NEW_REQUEST) {
   if (event == MG_NEW_REQUEST) {
-    // Echo requested URI back to the client
-    mg_printf(conn, "HTTP/1.1 200 OK\r\n"
-              "Content-Type: text/plain\r\n\r\n"
-              "%s", request_info->uri);
-    return "";  // Mark as processed
+    const char *content = "hello from mongoose!";
+    mg_printf(conn,
+              "HTTP/1.1 200 OK\r\n"
+              "Content-Type: text/plain\r\n"
+              "Content-Length: %d\r\n"        // Always set Content-Length
+              "\r\n"
+              "%s",
+              strlen(content),
+              content);
+    // Mark as processed
+    return "";
   } else {
   } else {
     return NULL;
     return NULL;
   }
   }