1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-07 16:02:55 +03:00

Renamed mg_ to httplib_

This commit is contained in:
Lammert Bies
2016-12-13 17:32:31 +01:00
parent 647139558b
commit d317ce3e82
178 changed files with 2173 additions and 2513 deletions

View File

@@ -10,22 +10,22 @@ static const char *html_form =
"<input type=\"submit\" />"
"</form></body></html>";
static int begin_request_handler(struct mg_connection *conn)
static int begin_request_handler(struct httplib_connection *conn)
{
const struct mg_request_info *ri = mg_get_request_info(conn);
const struct httplib_request_info *ri = httplib_get_request_info(conn);
char post_data[1024], input1[sizeof(post_data)], input2[sizeof(post_data)];
int post_data_len;
if (!strcmp(ri->uri, "/handle_post_request")) {
// User has submitted a form, show submitted data and a variable value
post_data_len = mg_read(conn, post_data, sizeof(post_data));
post_data_len = httplib_read(conn, post_data, sizeof(post_data));
// Parse form data. input1 and input2 are guaranteed to be NUL-terminated
mg_get_var(post_data, post_data_len, "input_1", input1, sizeof(input1));
mg_get_var(post_data, post_data_len, "input_2", input2, sizeof(input2));
httplib_get_var(post_data, post_data_len, "input_1", input1, sizeof(input1));
httplib_get_var(post_data, post_data_len, "input_2", input2, sizeof(input2));
// Send reply to the client, showing submitted form values.
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
httplib_printf(conn, "HTTP/1.0 200 OK\r\n"
"Content-Type: text/plain\r\n\r\n"
"Submitted data: [%.*s]\n"
"Submitted data length: %d bytes\n"
@@ -34,7 +34,7 @@ static int begin_request_handler(struct mg_connection *conn)
post_data_len, post_data, post_data_len, input1, input2);
} else {
// Show HTML form.
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
httplib_printf(conn, "HTTP/1.0 200 OK\r\n"
"Content-Length: %d\r\n"
"Content-Type: text/html\r\n\r\n%s",
(int) strlen(html_form), html_form);
@@ -44,15 +44,15 @@ static int begin_request_handler(struct mg_connection *conn)
int main(void)
{
struct mg_context *ctx;
struct httplib_context *ctx;
const char *options[] = {"listening_ports", "8080", NULL};
struct mg_callbacks callbacks;
struct httplib_callbacks callbacks;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = begin_request_handler;
ctx = mg_start(&callbacks, NULL, options);
ctx = httplib_start(&callbacks, NULL, options);
getchar(); // Wait until user hits "enter"
mg_stop(ctx);
httplib_stop(ctx);
return 0;
}