Compare commits
7 Commits
91ff743df9
...
6ceae16a20
Author | SHA1 | Date |
---|---|---|
Xavier Del Campo Romero | 6ceae16a20 | |
Xavier Del Campo Romero | 46a9d4efb9 | |
Xavier Del Campo Romero | 444563ca13 | |
Xavier Del Campo Romero | dd1589a5ea | |
Xavier Del Campo Romero | edc855f93b | |
Xavier Del Campo Romero | f9a305fe4d | |
Xavier Del Campo Romero | fcba916011 |
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.13.5)
|
||||
option(BUILD_EXAMPLES "Build examples" ON)
|
||||
project(web LANGUAGES C VERSION 0.1.0)
|
||||
project(web LANGUAGES C VERSION 0.2.0)
|
||||
add_library(${PROJECT_NAME}
|
||||
handler.c
|
||||
html.c
|
||||
|
@ -8,7 +8,7 @@ add_library(${PROJECT_NAME}
|
|||
server.c
|
||||
wildcard_cmp.c)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake)
|
||||
find_package(dynstr 0.1.0)
|
||||
find_package(dynstr 0.2.0)
|
||||
|
||||
if(NOT DYNSTR_FOUND)
|
||||
message(STATUS "Using in-tree dynstr")
|
||||
|
|
26
README.md
26
README.md
|
@ -12,7 +12,7 @@ portability, minimalism, simplicity and efficiency.
|
|||
## Features
|
||||
|
||||
- Small and portable HTTP/1.1 server implementation, with support for
|
||||
`GET` and `POST`.
|
||||
`GET`, `HEAD`, `PUT` and `POST`.
|
||||
- Provides a interface to set up user-defined callbacks depending on
|
||||
the operation (see example below).
|
||||
- Transport-agnostic implementation.
|
||||
|
@ -20,8 +20,8 @@ the operation (see example below).
|
|||
provided, the HTTP interface can be mapped to any other reliable
|
||||
transport layer.
|
||||
- Supports [`multiform/form-data`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)
|
||||
, which makes it useful to transfer large amounts of data, such as
|
||||
binary files.
|
||||
, which makes it useful to transfer multiple files with a single `POST`
|
||||
request.
|
||||
- [A library](include/libweb/html.h) to write HTML programmatically.
|
||||
|
||||
### TLS
|
||||
|
@ -56,6 +56,20 @@ sudo apt install build-essential
|
|||
sudo apt install cmake
|
||||
```
|
||||
|
||||
### Alpine Linux
|
||||
|
||||
#### Mandatory packages
|
||||
|
||||
```sh
|
||||
apk add make gcc musl-dev
|
||||
```
|
||||
|
||||
#### Optional packages
|
||||
|
||||
```sh
|
||||
apk add cmake
|
||||
```
|
||||
|
||||
## How to use
|
||||
### Build
|
||||
|
||||
|
@ -109,7 +123,7 @@ to integrate `libweb` into CMake projects via `add_subdirectory` and
|
|||
project(example)
|
||||
add_executable(${PROJECT_NAME} main.c)
|
||||
add_subdirectory(libweb)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE libweb)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE web)
|
||||
```
|
||||
|
||||
Additionally, `libweb` can be installed using the standard procedure
|
||||
|
@ -142,7 +156,7 @@ $ cmake --build .
|
|||
## Why this project?
|
||||
|
||||
Originally, `libweb` was part of the
|
||||
[`slcl`](https://gitea.privatedns.org/xavi92/slcl) project, a lightweight
|
||||
[`slcl`](https://gitea.privatedns.org/xavi/slcl) project, a lightweight
|
||||
cloud solution also written in C99 plus POSIX extensions. However, there
|
||||
always was a clear separation between application logic and the underlying
|
||||
HTTP/1.1 server implementation and other surrounding utilities.
|
||||
|
@ -178,7 +192,7 @@ essential for `slcl`.
|
|||
|
||||
```
|
||||
libweb, a simple and lightweight web framework.
|
||||
Copyright (C) 2023 libweb contributors
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HANDLER_ADD 3 2023-09-13 0.1.0 "libweb Library Reference"
|
||||
.TH HANDLER_ADD 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
handler_add \- add an endpoint to a web server handler object
|
||||
|
@ -81,7 +81,7 @@ for a list of possible errors.
|
|||
.BR libweb_handler (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 libweb contributors.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HANDLER_ALLOC 3 2023-11-16 0.2.0 "libweb Library Reference"
|
||||
.TH HANDLER_ALLOC 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
handler_alloc \- allocate a web server handler object
|
||||
|
@ -52,7 +52,7 @@ for a list of possible errors.
|
|||
.BR libweb_handler (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 libweb contributors.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HANDLER_FREE 3 2023-09-14 0.1.0 "libweb Library Reference"
|
||||
.TH HANDLER_FREE 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
handler_free \- free a web server handler object
|
||||
|
@ -32,7 +32,7 @@ No errors are defined.
|
|||
.BR libweb_handler (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HANDLER_LISTEN 3 2023-11-16 0.2.0 "libweb Library Reference"
|
||||
.TH HANDLER_LISTEN 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
handler_listen \- initialize server to listen to a given port
|
||||
|
@ -48,7 +48,7 @@ No errors are defined.
|
|||
.BR signal (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 libweb contributors.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HANDLER_LOOP 3 2023-11-16 0.2.0 "libweb Library Reference"
|
||||
.TH HANDLER_LOOP 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
handler_loop \- listen to and handle incoming connections on a web
|
||||
|
@ -67,7 +67,7 @@ similarly to its member
|
|||
.BR signal (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 libweb contributors.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTML_NODE_ADD_ATTR 3 2023-09-24 0.1.0 "libweb Library Reference"
|
||||
.TH HTML_NODE_ADD_ATTR 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
html_node_add_attr \- add attribute to a HTML node
|
||||
|
@ -69,7 +69,7 @@ No errors are defined.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTML_NODE_ADD_CHILD 3 2023-09-25 0.1.0 "libweb Library Reference"
|
||||
.TH HTML_NODE_ADD_CHILD 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
html_node_add_child \- add child to a HTML node
|
||||
|
@ -116,7 +116,7 @@ from a child node when a node already has one.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTML_NODE_ADD_SIBLING 3 2023-09-25 0.1.0 "libweb Library Reference"
|
||||
.TH HTML_NODE_ADD_SIBLING 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
html_node_add_sibling \- add sibling to a HTML node
|
||||
|
@ -47,7 +47,7 @@ was still made public so as to cover possibly less common use cases.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTML_NODE_ALLOC 3 2023-09-15 0.1.0 "libweb Library Reference"
|
||||
.TH HTML_NODE_ALLOC 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
html_node_alloc \- allocate a HTML node
|
||||
|
@ -67,7 +67,7 @@ it via
|
|||
.BR libweb_html (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTML_NODE_FREE 3 2023-09-16 0.1.0 "libweb Library Reference"
|
||||
.TH HTML_NODE_FREE 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
html_node_free \- free a HTML node and its children
|
||||
|
@ -40,7 +40,7 @@ for a child node.
|
|||
.BR libweb_html (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTML_NODE_SET_VALUE 3 2023-09-24 0.1.0 "libweb Library Reference"
|
||||
.TH HTML_NODE_SET_VALUE 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
html_node_set_value \- set value to a HTML node
|
||||
|
@ -72,7 +72,7 @@ No errors are defined.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTML_NODE_SET_VALUE_UNESCAPED 3 2023-09-24 0.1.0 "libweb Library Reference"
|
||||
.TH HTML_NODE_SET_VALUE_UNESCAPED 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
html_node_set_value_unescaped \- set value to a HTML node
|
||||
|
@ -73,7 +73,7 @@ No errors are defined.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTML_SERIALIZE 3 2023-09-24 0.1.0 "libweb Library Reference"
|
||||
.TH HTML_SERIALIZE 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
html_serialize \- add attribute to a HTML node
|
||||
|
@ -44,7 +44,7 @@ No errors are defined.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTTP_ALLOC 3 2023-09-06 0.1.0 "libweb Library Reference"
|
||||
.TH HTTP_ALLOC 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
http_alloc \- allocate a HTTP context object
|
||||
|
@ -54,7 +54,7 @@ This function is designed for internal use by
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTTP_COOKIE_CREATE 3 2023-09-07 0.1.0 "libweb Library Reference"
|
||||
.TH HTTP_COOKIE_CREATE 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
http_cookie_create \- creates a HTTP/1.1 cookie
|
||||
|
@ -60,7 +60,7 @@ expiration date as an additional parameter to
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTTP_DECODE_URL 3 2023-11-11 0.2.0 "libweb Library Reference"
|
||||
.TH HTTP_DECODE_URL 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
http_decode_url \- decodes a percent-encoded null-terminated string
|
||||
|
@ -33,7 +33,7 @@ No errors are defined.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTTP_ENCODE_URL 3 2023-09-07 0.1.0 "libweb Library Reference"
|
||||
.TH HTTP_ENCODE_URL 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
http_encode_url \- allocates a percent-encoded null-terminated string
|
||||
|
@ -30,7 +30,7 @@ No errors are defined.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTTP_FREE 3 2023-09-06 0.1.0 "libweb Library Reference"
|
||||
.TH HTTP_FREE 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
http_free \- free a HTTP context object
|
||||
|
@ -33,7 +33,7 @@ No errors are defined.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTTP_RESPONSE_ADD_HEADER 3 2023-09-07 0.1.0 "libweb Library Reference"
|
||||
.TH HTTP_RESPONSE_ADD_HEADER 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
http_response_add_header \- adds a HTTP/1.1 header to a response
|
||||
|
@ -45,7 +45,7 @@ for a list of possible errors.
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH HTTP_UPDATE 3 2023-09-06 0.1.0 "libweb Library Reference"
|
||||
.TH HTTP_UPDATE 3 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
http_update \- updates a HTTP context object
|
||||
|
@ -68,7 +68,7 @@ This function is designed for internal use by
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH LIBWEB_HANDLER 7 2023-11-18 0.2.0 "libweb Library Reference"
|
||||
.TH LIBWEB_HANDLER 7 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
libweb_handler \- libweb high-level website configuration
|
||||
|
@ -236,7 +236,7 @@ end:
|
|||
.BR libweb_http (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 libweb contributors.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH LIBWEB_HTML 7 2023-09-15 0.1.0 "libweb Library Reference"
|
||||
.TH LIBWEB_HTML 7 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
libweb_html \- libweb HTML serializer
|
||||
|
@ -35,7 +35,7 @@ plus all of the memory allocated by its children.
|
|||
.IR html_node_set_value (3)
|
||||
sets the HTML value for a
|
||||
.I struct html_node
|
||||
object, escaping characters that could case syntax errors, such as
|
||||
object, escaping characters that could cause syntax errors, such as
|
||||
.B <
|
||||
.BR "" ( "LESS-THAN SIGN" ).
|
||||
|
||||
|
@ -170,7 +170,7 @@ This program should write the following data over standard output:
|
|||
.BR libweb_html (7).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH LIBWEB_HTTP 7 2023-11-18 0.2.0 "libweb Library Reference"
|
||||
.TH LIBWEB_HTTP 7 2024-02-12 0.2.0 "libweb Library Reference"
|
||||
|
||||
.SH NAME
|
||||
libweb_http \- libweb HTTP connection handling and utilities
|
||||
|
@ -19,14 +19,23 @@ server implementation, the following features are supported:
|
|||
.IP \(bu 2
|
||||
.BR GET .
|
||||
.IP \(bu 2
|
||||
.BR POST .
|
||||
.BR HEAD .
|
||||
.IP \(bu 2
|
||||
.BR PUT .
|
||||
.IP \(bu 2
|
||||
.BR POST .
|
||||
.IR multipart/form-data -encoded
|
||||
data. An optional payload size limit can be defined (see section
|
||||
.BR "HTTP server configuration" ).
|
||||
data is also supported.
|
||||
.IP \(bu 2
|
||||
Cookies.
|
||||
|
||||
An optional payload size limit can be defined for
|
||||
.B PUT
|
||||
and
|
||||
.B POST
|
||||
requests (see section
|
||||
.BR "HTTP server configuration" ).
|
||||
|
||||
.SS Utility functions
|
||||
The functions listed below are meant for library users:
|
||||
|
||||
|
@ -154,13 +163,20 @@ returned.
|
|||
is a function pointer called by
|
||||
.I libweb
|
||||
when an incoming HTTP request from a client requires to store one or
|
||||
more files on the server, encoded as
|
||||
.IR multipart/form-data .
|
||||
more files on the server.
|
||||
In the case of a
|
||||
.B POST
|
||||
request,
|
||||
.I len
|
||||
defines the length of the
|
||||
.IR multipart/form-data
|
||||
(see section
|
||||
.BR "Content-Length design limitations for multipart/form-data" ).
|
||||
In the case of a
|
||||
.B PUT
|
||||
request,
|
||||
.I len
|
||||
defines the length of the file body.
|
||||
.I c
|
||||
is a read-only pointer to a
|
||||
.I "struct http_cookie"
|
||||
|
@ -230,12 +246,13 @@ struct http_payload
|
|||
union
|
||||
{
|
||||
struct http_post \fIpost\fP;
|
||||
} \fIu\fP;
|
||||
struct http_put \fIput\fP;
|
||||
} u;
|
||||
|
||||
const struct http_arg *\fIargs\fP;
|
||||
size_t \fIn_args\fP;
|
||||
size_t \fIn_args\fP, \fIn_headers\fP;
|
||||
const struct http_header *\fIheaders\fP;
|
||||
size_t \fIn_headers\fP;
|
||||
bool \fIexpect_continue\fP;
|
||||
};
|
||||
.EE
|
||||
.in
|
||||
|
@ -263,9 +280,13 @@ defines a tagged union with operation-specific data. For example,
|
|||
refers to data sent by a client on a
|
||||
.B POST
|
||||
request (see section
|
||||
.BR "HTTP POST payload" ).
|
||||
Also, see section
|
||||
.BR "Future supported HTTP/1.1 operations" .
|
||||
.BR "HTTP POST payload" ),
|
||||
whereas
|
||||
.I put
|
||||
refers to data sent by a client on a
|
||||
.B PUT
|
||||
request (see section
|
||||
.BR "HTTP PUT payload" ).
|
||||
|
||||
.I args
|
||||
defines a list of key-value pairs containing URL parameters. Its length
|
||||
|
@ -277,6 +298,21 @@ defines a list of key-value pairs containing header fields. Its length
|
|||
is defined by
|
||||
.IR n_headers .
|
||||
|
||||
.I expect_continue
|
||||
shall be set to
|
||||
.I true
|
||||
if an
|
||||
.B "Expect: 100-continue"
|
||||
HTTP header is received,
|
||||
.I false
|
||||
otherwise (see section
|
||||
.BR "Expect: 100-continue handling" ).
|
||||
This field is only relevant for
|
||||
.B PUT
|
||||
or
|
||||
.B POST
|
||||
requests.
|
||||
|
||||
.SS HTTP POST payload
|
||||
|
||||
As opposed to payload-less HTTP/1.1 operations, such as
|
||||
|
@ -284,7 +320,7 @@ As opposed to payload-less HTTP/1.1 operations, such as
|
|||
.B POST
|
||||
operations might or might not include payload data. Moreover, such
|
||||
payload can be encoded in two different ways, which
|
||||
.I slcl
|
||||
.I libweb
|
||||
handles differently:
|
||||
|
||||
.IP \(bu 2
|
||||
|
@ -309,7 +345,7 @@ member
|
|||
.IR tmpdir .
|
||||
|
||||
This information is contained into a
|
||||
.B "struct http_post"
|
||||
.I struct http_post
|
||||
object, defined as:
|
||||
|
||||
.PP
|
||||
|
@ -317,7 +353,6 @@ object, defined as:
|
|||
.EX
|
||||
struct http_post
|
||||
{
|
||||
bool \fIexpect_continue\fP;
|
||||
const char *\fIdata\fP;
|
||||
size_t \fInfiles\fP, \fInpairs\fP;
|
||||
|
||||
|
@ -335,19 +370,6 @@ struct http_post
|
|||
.in
|
||||
.PP
|
||||
|
||||
.I expect_continue
|
||||
shall be set to
|
||||
.I true
|
||||
if an
|
||||
.B "Expect: 100-continue"
|
||||
HTTP header is received,
|
||||
.I false
|
||||
otherwise (see
|
||||
section
|
||||
.B Handling of 100-continue requests
|
||||
in
|
||||
.BR BUGS ).
|
||||
|
||||
When
|
||||
.IR application/x-www-form-urlencoded -data
|
||||
is included,
|
||||
|
@ -391,6 +413,94 @@ If no name-value pairs are defined,
|
|||
.I pairs
|
||||
shall be a null pointer.
|
||||
|
||||
.SS HTTP PUT payload
|
||||
|
||||
For
|
||||
.B PUT
|
||||
requests, and as opposed to
|
||||
.B POST
|
||||
requests,
|
||||
.I libweb
|
||||
shall always store the request body into a temporary file, defined by
|
||||
.I struct http_put
|
||||
member
|
||||
.IR tmpname .
|
||||
|
||||
This information is contained into a
|
||||
.I struct http_put
|
||||
object, defined as:
|
||||
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
struct http_put
|
||||
{
|
||||
const char *tmpname;
|
||||
};
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
|
||||
.SS Expect: 100-continue handling
|
||||
|
||||
As opposed to other HTTP headers, the
|
||||
.B Expect: 100-continue
|
||||
HTTP header requires the server to respond before the request body is
|
||||
sent by the client. Typically, this is meant to allow the server to
|
||||
check the request resource and headers beforehand, without waiting to
|
||||
receive the request body, which can be long. This is usual for resource
|
||||
uploads, as typically done with
|
||||
.BR PUT
|
||||
requests.
|
||||
|
||||
Therefore, when this header is received,
|
||||
.I libweb
|
||||
shall trigger the user-defined callback as defined by
|
||||
.I struct http_cfg
|
||||
member
|
||||
.I payload
|
||||
at least once. Then, users are expected to check this flag and act
|
||||
accordingly.
|
||||
|
||||
The example below shows a user-defined callback that replies with
|
||||
.I HTTP_STATUS_CONTINUE
|
||||
when
|
||||
.I struct http_payload
|
||||
member
|
||||
.I expect_continue
|
||||
is set:
|
||||
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
static int on_payload(const struct http_payload *const p,
|
||||
struct http_response *const r, void *const user)
|
||||
{
|
||||
if (p->expect_continue)
|
||||
{
|
||||
*r = (const struct http_response)
|
||||
{
|
||||
.status = HTTP_STATUS_CONTINUE
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Handle request body. */
|
||||
}
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
|
||||
Then, once the request body is received,
|
||||
.I libweb
|
||||
shall trigger the callback again with
|
||||
.I struct http_payload
|
||||
member
|
||||
.I expect_continue
|
||||
assigned to
|
||||
.IR false .
|
||||
|
||||
.SS HTTP responses
|
||||
|
||||
Some function pointers used by
|
||||
|
@ -579,22 +689,6 @@ can rely on, and therefore is the value passed to the
|
|||
function pointer in
|
||||
.IR "struct http_cfg" .
|
||||
|
||||
.SH BUGS
|
||||
.SS Handling of 100-continue requests
|
||||
|
||||
The handling of
|
||||
.B 100-continue
|
||||
requests is not done correctly:
|
||||
.I libweb
|
||||
calls the function pointed to by
|
||||
.I "struct http_cfg"
|
||||
member
|
||||
.I payload
|
||||
as soon as it encounters the
|
||||
.B Expected:
|
||||
header. However, a response should only be sent to the client once all
|
||||
headers are processed.
|
||||
|
||||
.SH FUTURE DIRECTIONS
|
||||
.SS Limitations on the number of HTTP cookies
|
||||
So far,
|
||||
|
@ -630,23 +724,6 @@ member
|
|||
with an array of structures containing key-value pairs, so that
|
||||
applications no longer need to decode payload data by themselves.
|
||||
|
||||
.SS Future supported HTTP/1.1 operations
|
||||
So far,
|
||||
.I struct http_payload
|
||||
defines
|
||||
.I u
|
||||
as a union that only holds one possible data type. While this might
|
||||
look counterintuitive, this is because
|
||||
.B POST
|
||||
is the only HTTP/1.1 operation
|
||||
.I libweb
|
||||
supports that requires to store a payload. However, future versions of
|
||||
this library might extend its support for other HTTP/1.1 operations
|
||||
that could require to store a payload, while keeping the memory
|
||||
footprint for
|
||||
.I struct http_payload
|
||||
small.
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR handler_alloc (3),
|
||||
.BR http_alloc (3),
|
||||
|
@ -658,7 +735,7 @@ small.
|
|||
.BR http_decode_url (3).
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 Xavier Del Campo Romero.
|
||||
Copyright (C) 2023-2024 libweb contributors
|
||||
.P
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
Loading…
Reference in New Issue