mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-25 03:29:00 +08:00
35 lines
879 B
C
35 lines
879 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "mongoose.h"
|
|
|
|
static void *callback(enum mg_event event,
|
|
struct mg_connection *conn,
|
|
const struct mg_request_info *request_info) {
|
|
if (event == MG_NEW_REQUEST) {
|
|
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 {
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
int main(void) {
|
|
struct mg_context *ctx;
|
|
const char *options[] = {"listening_ports", "8080", NULL};
|
|
|
|
ctx = mg_start(&callback, NULL, options);
|
|
getchar(); // Wait until user hits "enter"
|
|
mg_stop(ctx);
|
|
|
|
return 0;
|
|
}
|