1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//! # Rust bindings for NGINX
//!
//! The `ngx` crate provides a high-level Rust interface for the [NGINX] C APIs,
//! allowing creation of NGINX dynamic modules completely in Rust.
//!
//! [NGINX]: https://nginx.org/
//!
//! ## Project status
//!
//! This project is in active development. It is stable enough to be used in our
//! own products, but the APIs are not stabilized and breaking changes are expected.
//!
//! ## Build
//!
//! NGINX modules can be built against a particular version of NGINX. The following
//! environment variables can be used to specify the NGINX build to use:
//!
//! - `NGINX_BUILD_DIR` - absolute path to the NGINX build directory.
//! Usually it's `objs` under the source directory, but can be changed with the
//! `--builddir=` argument of the configure script.
//!
//! - `NGINX_SOURCE_DIR` - absolute path to the NGINX source directory, configured
//! with the [`configure`](https://nginx.org/en/docs/configure.html) command.
//!
//! Only the `./configure` step of the NGINX build is mandatory because bindings
//! generator don't depend on any of the artifacts generated by `make`.
//!
//! For example, this is how you would compile the [examples](#examples) using a
//! specific version of NGINX:
//!
//! ```sh
//! NGINX_BUILD_DIR=/path/to/nginx-1.28.0/objs cargo build --package=examples --examples
//! ```
//!
//! ### Building with the NGINX build script
//!
//! You can build your Rust-based module as a part of the NGINX build process by
//! providing a `config` script implementation and passing the `--add-module`/
//! `--add-dynamic-module` options to the configure script.
//!
//! See the following example integration scripts: [`examples/config`] and
//! [`examples/config.make`].
//!
//! [`examples/config`]: https://github.com/bavshin-f5/ngx-rust/blob/main/examples/config
//! [`examples/config.make`]: https://github.com/bavshin-f5/ngx-rust/blob/main/examples/config.make
//!
//! ### Building with vendored NGINX sources
//!
//! It is possible to build module with a vendored copy of the NGINX sources
//! provided in the `nginx-src` crate by enabling feature `vendored`:
//!
//! By default, this will use the latest stable release of NGINX and require
//! system-wide installation of build dependencies (OpenSSL, PCRE2, Zlib).
//!
//! The behavior of vendored builds can be customized with environment variables,
//! as documented in the [nginx-src] crate README.
//!
//! **NOTE**: We recommend to build the module binaries against the exact source and
//! configuration of the NGINX build that you are planning to use in production,
//! and that is unlikely to be possible with the vendored source.
//!
//! `configure` arguments alter the APIs and the symbols visible to the Rust code,
//! and some OS distributions are known to ship nginx packages with API-breaking
//! patches applied.
//!
//! [nginx-src]: https://docs.rs/nginx-src/
//!
//! ## Cargo features
//!
//! - `alloc` - **Enabled** by default. This provides APIs that require allocations
//! via the `alloc` crate.
//! - `async` - Enables a minimal async runtime built on top of the NGINX event loop.
//! - `serde` - Enables serialization support for some of the provided and
//! re-exported types.
//! - `std` - **Enabled** by default. This provides APIs that require the standard
//! library.
//! - `vendored`: Enables the build scripts to build a copy of nginx source and link
//! against it. See the [nginx-src] crate documentation for additional details.
//!
//! ## Dependencies
//!
//! The following dependencies are required to build a Rust NGINX module on Linux
//! or BSD platform:
//!
//! - NGINX build dependencies: C compiler, make, OpenSSL, PCRE2, and Zlib.
//! - Rust toolchain (1.81.0 or later)
//! - [libclang] for rust-bindgen
//!
//! The installation process and the package names are system-dependent. Please,
//! consult the documentation for your distribution.
//!
//! Note that on some systems you will need `-devel` or `-dev` versions of the
//! packages.
//!
//! For example, [Dockerfile] contains the installation commands for Debian Linux.
//!
//! [Dockerfile]: https://github.com/nginx/ngx-rust/blob/main/Dockerfile
//! [libclang]: https://rust-lang.github.io/rust-bindgen/requirements.html
//!
//! ### macOS dependencies
//!
//! In order to use the optional GNU make build process on macOS, you will need
//! to install additional tools. This can be done via [homebrew](https://brew.sh/)
//! with the following command:
//!
//! ```sh
//! brew install make openssl grep
//! ```
//!
//! Additionally, you may need to set up LLVM and clang. Typically, this is done
//! as follows:
//!
//! ```sh
//! # make sure xcode tools are installed
//! xcode-select --install
//! # instal llvm
//! brew install --with-toolchain llvm
//! ```
extern crate alloc;
/// The core module.
///
/// This module provides fundamental utilities needed to interface with many NGINX primitives.
/// String conversions, the pool (memory interface) object, and buffer APIs are covered here. These
/// utilities will generally align with the NGINX 'core' files and APIs.
/// The ffi module.
///
/// This module provides scoped FFI bindings for NGINX symbols.
/// The http module.
///
/// This modules provides wrappers and utilities to NGINX http APIs, such as requests,
/// configuration access, and statuses.
/// The log module.
///
/// This module provides an interface into the NGINX logger framework.
/// Define modules exported by this library.
///
/// These are normally generated by the Nginx module system, but need to be
/// defined when building modules outside of it.
/// Count number of arguments