
Handing a web request with Mongoose
By:
ColonelPanic on
Apr 24th, 2012 | syntax:
C | size: 0.90 KB | hits: 39 | expires: Never
char const *kHeader = "HTTP/1.1 200 OK\r\n"
"Content-Type: %s\r\n"
"Content-Length: %d\r\n"
"\r\n";
static void *eventHandler(enum mg_event event, struct mg_connection *connection, const struct mg_request_info *requestInfo)
{
void *processed = "done";
switch(event)
{
case MG_NEW_REQUEST:
NSLog(@"%s", requestInfo->uri);
char *content = "Hello world!\n";
char *mimeType = "text/plain";
size_t contentLength = strlen(content);
mg_printf(connection, kHeader, mimeType, contentLength);
mg_write(connection, content, contentLength);
break;
default:
NSLog(@"Unsupported event, letting Mongoose take care of it!");
processed = NULL;
break;
}
return processed;
}