mirror of
https://github.com/lammertb/libhttp.git
synced 2025-07-31 08:24:23 +03:00
Alternative to mg_upload (Step 4/?)
This commit is contained in:
@ -63,6 +63,9 @@ ExampleHandler(struct mg_connection *conn, void *cbdata)
|
|||||||
mg_printf(conn,
|
mg_printf(conn,
|
||||||
"<p>To see a page from the *.foo handler <a "
|
"<p>To see a page from the *.foo handler <a "
|
||||||
"href=\"xy.foo\">click xy.foo</a></p>");
|
"href=\"xy.foo\">click xy.foo</a></p>");
|
||||||
|
mg_printf(conn,
|
||||||
|
"<p>To see a page from the FileHandler handler <a "
|
||||||
|
"href=\"form\">click form</a> (this is the form test page)</p>");
|
||||||
#ifdef USE_WEBSOCKET
|
#ifdef USE_WEBSOCKET
|
||||||
mg_printf(conn,
|
mg_printf(conn,
|
||||||
"<p>To test websocket handler <a href=\"/websocket\">click "
|
"<p>To test websocket handler <a href=\"/websocket\">click "
|
||||||
@ -141,6 +144,34 @@ FooHandler(struct mg_connection *conn, void *cbdata)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
FileHandler(struct mg_connection *conn, void *cbdata)
|
||||||
|
{
|
||||||
|
/* In this handler, we ignore the req_info and send the file "fileName". */
|
||||||
|
const char *fileName = (const char*)cbdata;
|
||||||
|
|
||||||
|
mg_send_file(conn, fileName);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
FormHandler(struct mg_connection *conn, void *cbdata)
|
||||||
|
{
|
||||||
|
/* Handler may access the request info using mg_get_request_info */
|
||||||
|
const struct mg_request_info *req_info = mg_get_request_info(conn);
|
||||||
|
int ret;
|
||||||
|
struct mg_form_data_handler *fdh = 0;
|
||||||
|
|
||||||
|
/* TODO: Checks before calling handle_form_data ? */
|
||||||
|
(void)req_info;
|
||||||
|
|
||||||
|
ret = handle_form_data(conn, fdh);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
WebSocketStartHandler(struct mg_connection *conn, void *cbdata)
|
WebSocketStartHandler(struct mg_connection *conn, void *cbdata)
|
||||||
{
|
{
|
||||||
@ -389,6 +420,15 @@ main(int argc, char *argv[])
|
|||||||
/* Add handler for all files with .foo extention */
|
/* Add handler for all files with .foo extention */
|
||||||
mg_set_request_handler(ctx, "**.foo$", FooHandler, 0);
|
mg_set_request_handler(ctx, "**.foo$", FooHandler, 0);
|
||||||
|
|
||||||
|
/* Add handler for /form (serve a file outside the document root) */
|
||||||
|
mg_set_request_handler(ctx, "/form", FileHandler, (void *)"../../test/form.html");
|
||||||
|
|
||||||
|
/* Add handler for form data */
|
||||||
|
mg_set_request_handler(ctx,
|
||||||
|
"/handle_form.embedded_c.example.callback",
|
||||||
|
FormHandler,
|
||||||
|
(void *)0);
|
||||||
|
|
||||||
/* Add HTTP site to open a websocket connection */
|
/* Add HTTP site to open a websocket connection */
|
||||||
mg_set_request_handler(ctx, "/websocket", WebSocketStartHandler, 0);
|
mg_set_request_handler(ctx, "/websocket", WebSocketStartHandler, 0);
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
<form action="/handle_form.lua">
|
<form action="/handle_form.embedded_c.example.callback">
|
||||||
See <a href="http://www.w3schools.com/html/html_form_input_types.asp">HTML form tutorial</a>.<br />
|
See <a href="http://www.w3schools.com/html/html_form_input_types.asp">HTML form tutorial</a>.<br />
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
@ -89,6 +89,9 @@
|
|||||||
<textarea name="message" rows="10" cols="30">Text area default text.</textarea>
|
<textarea name="message" rows="10" cols="30">Text area default text.</textarea>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<input type="submit" value="Submit to Lua script" formmethod="POST" formenctype="multipart/form-data"
|
||||||
|
formaction="/handle_form.lua">
|
||||||
|
|
||||||
<input type="submit" value="Submit (form default)">
|
<input type="submit" value="Submit (form default)">
|
||||||
<input type="submit" value="Submit (GET)" formmethod="GET">
|
<input type="submit" value="Submit (GET)" formmethod="GET">
|
||||||
<input type="submit" value="Submit (POST)" formmethod="POST">
|
<input type="submit" value="Submit (POST)" formmethod="POST">
|
||||||
|
Reference in New Issue
Block a user