ngx_str_t is a string format customized by nginx, which is defined in ngx_string.h as follows:
typedef struct {
size_t len; //字符串长度,不含'\0'
u_char *data; //真正字符串
} ngx_str_t;
It is essentially a structure, and this format string is widely used in nginx.
Advantages: Reduce the number of times of string length calculations. As a web server, nginx will calculate the length of a large number of characters; it can be referenced at any time, reducing the performance loss caused by string copying.
For the operation of such strings, nginx also provides a series of operation functions, which are defined in nginx_string.[c|h]:
#define ngx_string (str) { sizeof(str) - 1, (u_char *) str }
will It is a normal string converted to an nginx string format, such as
ngx_str_t name = ngx_string("http"); // Note that name is a structure, not a pointer, after macro preprocessing, it is equivalent to
ngx_str_t name = {sizeof(" http”)-1, (u_char*)”http”};