mirror of
https://github.com/lammertb/libhttp.git
synced 2025-07-31 08:24:23 +03:00
Alternative to mg_upload (Step 5/?)
This commit is contained in:
@ -421,7 +421,10 @@ main(int argc, char *argv[])
|
|||||||
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) */
|
/* Add handler for /form (serve a file outside the document root) */
|
||||||
mg_set_request_handler(ctx, "/form", FileHandler, (void *)"../../test/form.html");
|
mg_set_request_handler(ctx,
|
||||||
|
"/form",
|
||||||
|
FileHandler,
|
||||||
|
(void *)"../../test/form.html");
|
||||||
|
|
||||||
/* Add handler for form data */
|
/* Add handler for form data */
|
||||||
mg_set_request_handler(ctx,
|
mg_set_request_handler(ctx,
|
||||||
|
@ -27,3 +27,4 @@ clang-format -i test/shared.c
|
|||||||
clang-format -i test/civetweb_check.h
|
clang-format -i test/civetweb_check.h
|
||||||
clang-format -i test/main.c
|
clang-format -i test/main.c
|
||||||
|
|
||||||
|
clang-format -i examples/embedded_c/embedded_c.c
|
||||||
|
@ -32,10 +32,21 @@ handle_form_data(struct mg_connection *conn, struct mg_form_data_handler *fdh)
|
|||||||
(conn->request_info.content_length > 0) || (conn->is_chunked);
|
(conn->request_info.content_length > 0) || (conn->is_chunked);
|
||||||
char *data;
|
char *data;
|
||||||
|
|
||||||
|
/* There are three ways to encode data from a HTML form:
|
||||||
|
* 1) method: GET (default)
|
||||||
|
* The form data is in the HTTP query string.
|
||||||
|
* 2) method: POST, enctype: "application/x-www-form-urlencoded"
|
||||||
|
* The form data is in the request body.
|
||||||
|
* The body is url encoded (the default encoding for POST).
|
||||||
|
* 3) method: POST, enctype: "multipart/form-data".
|
||||||
|
* The form data is in the request body of a multipart message.
|
||||||
|
* This is the typical way to handle file upload from a form.
|
||||||
|
*/
|
||||||
|
|
||||||
content_type = mg_get_header(conn, "Content-Type");
|
content_type = mg_get_header(conn, "Content-Type");
|
||||||
if (content_type == NULL) {
|
if (content_type == NULL) {
|
||||||
/* This request does not have a content type set */
|
/* This request does not have a content type set .. TODO: but it could be a GET requst */
|
||||||
return 0;
|
//return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mg_strcasecmp(content_type, "APPLICATION/X-WWW-FORM-URLENCODED")) {
|
if (!mg_strcasecmp(content_type, "APPLICATION/X-WWW-FORM-URLENCODED")) {
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
|
|
||||||
<form action="/handle_form.embedded_c.example.callback">
|
<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>
|
||||||
|
and <a href="http://www.w3.org/TR/html401/interact/forms.html">HTML spec</a>.<br />
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Text inputs:</legend>
|
<legend>Text inputs:</legend>
|
||||||
@ -89,14 +90,27 @@
|
|||||||
<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"
|
<fieldset>
|
||||||
|
<legend>Submit:</legend>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Submit to Lua script:</legend>
|
||||||
|
This will only work if server side Lua scripting is activated and /handle_form.lua can be found on the server.
|
||||||
|
<br>
|
||||||
|
<input type="submit" value="Submit" formmethod="POST" formenctype="multipart/form-data"
|
||||||
formaction="/handle_form.lua">
|
formaction="/handle_form.lua">
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend>Submit to callback:</legend>
|
||||||
|
This will only work in the embedded_c example.
|
||||||
|
<br>
|
||||||
<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">
|
||||||
<input type="submit" value="Submit (POST, url-encoded)" formmethod="POST" formenctype="application/x-www-form-urlencoded">
|
<input type="submit" value="Submit (POST, url-encoded)" formmethod="POST" formenctype="application/x-www-form-urlencoded">
|
||||||
<input type="submit" value="Submit (POST, form-data)" formmethod="POST" formenctype="multipart/form-data">
|
<input type="submit" value="Submit (POST, form-data)" formmethod="POST" formenctype="multipart/form-data">
|
||||||
|
</fieldset>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
Reference in New Issue
Block a user