liveBook · Manning

Ngx_http_read_client_request_body

As explained in Refactoring to Rust

ngx_http_read_client_request_body is an NGINX HTTP API function that asynchronously reads a client request body and invokes a completion callback.

ngx_http_read_client_request_body loads an NGINX client request body asynchronously, then invokes a supplied callback with the request pointer. HTTP handlers cannot assume the body is already loaded. section 4.4

Callback-based request handler

The handler calls ngx_http_read_client_request_body(r, Some(read_body_handler)) and returns 0 when accepted. The callback converts the request pointer to a reference, parses the body, and logs it; parsing errors stop processing safely.

How Refactoring to Rust covers it

How deep it goes
Explains the C-compatible callback signature, return handling, pointer checks, buffer traversal, and UTF-8 validation.
Examples
Uses Listing 4.8, null-request handling, request-body buffer traversal, and invalid-UTF-8 error handling.
What it assumes
Teaches the required Rust FFI annotations and pointer handling while assuming familiarity with NGINX request handlers and C-compatible types.
What you can do after
Build it from scratch by wiring an NGINX handler to an asynchronous body callback and safely extracting UTF-8 content.
How it connects
Connects NGINX HTTP handlers with callbacks, C FFI, unsafe Rust, request buffers, and UTF-8 conversion.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.