Excerpted from: http://blog.csdn.net/xiajun07061225/article/details/9189505 Jiang Yuyanyun’s blog
ngx_http_request_s is a very important structure in nginx, which runs through the entire process of http request processing.
The following explains the important member variables related to the HTTP framework in the ngx_http_request_s structure.
[cpp] view plaincopyprint?
- structngx_http_request_s {
- uint32_t signature;/* "HTTP" */
- //Request the corresponding client connection
- ngx_connection_t *connection;
- //Array of pointers to context structures that store all HTTP modules
- //Array of pointers pointing to the main level configuration structure corresponding to the request
- void**main_conf;
- //Pointer to the srv level configuration structure corresponding to the request Array
- voidPointer array of loc level configuration structure
- voidloc_conf;
- /*
- But if this method cannot handle all the business of the request at one time, after returning control to the epoll time module, when the request is called back again,
- will be processed through the Ngx_http_request_handler method, The processing of readable events in this method is to call read_event_handler to process the request.
- That is to say, the http module hopes to reimplement the read_event_handler method when processing the requested read event at the bottom layer
- */
- ngx _http_event_handler_pt read_event_handler; /Similar to the above method
- ngx_http_event_handler_pt write_event_handler;
- #if (NGX_HTTP_CACHE)
- ngx_http_cache_t *cache;
- #endif
/
- // The structure used by the upstream mechanismngx_http_upstream_t*upstream;ngx_array_t*upstream_states;
- *pool;
- //Buffer used to receive http request content, mainly receiving http headers Department
- ngx_buf_t *header_in;
- After http_process_request_headers receives and parses the headers of the http request, it will add each parsed http header to headers_in. In the headers linked list, other members in headers_in will be constructed at the same time
- ngx_http_headers_in_t headers_in;
- //The http module will put the http corresponding information you want to send into headers_out , expecting the http framework to headers_out The members in are serialized into http response packets and sent to the user
- ngx_http_headers_out_t headers_out;
- //Receive request The data structure of the body
- ngx_http_request_body_t * Request_body;
- // Delaying the time to close the connection
Time_t
- lingering_time;
// The current request initialization time
- //The following 9 members are the information parsed by the function ngx_http_process_request_line method when receiving and parsing the http request line
- ngx_uint_t ngx_uint_t method;//Method name
- ngx_uint_t http_version ; 议 // Protocol version
- ngx_str_t request_line;
- ngx_str_t uri;// Uri
- ngx_str_t args in the user request;// User request request The url parameter in the middle
ngx_str_t exten;
- // The file requested by the user expansion namengx_str_t unparsed_uri;// The original request without URL decoding
- ngx_str_t ngx_str_t method_name;//Method name string in user request
- ngx_str_t http_protocol;//The data member points to the http starting address in the request
- /* represents the http response that needs to be sent to the client. out holds the TCP stream representing the http header serialized in headers_out.
- * After calling the ngx_http_output_filter method, the http package body to be sent will also be saved in out, which is the key to asynchronously sending http responses. */
- ngx_chain_t *out;
- /*The current request may be a request sent by the user or a derived sub-request.
- * And main identifies the original request of a series of related derived sub-requests.通过 可*generally can determine whether the current request is the original request sent by the user through the same requests.*/
- ngx_http_request_t *main;
- //The parent request of the current request (not necessarily the original request)
- ngx_http_request_t *parent;
- // Functions related to subrequest sub-requests
- ngx_http_postponed_request_t *postponed;
- ngx_http_post_subrequest_t *post_subrequest;
- //All sub-requests are linked through this singly linked list
- ngx_http_posted_request_t *posted_requests;
- /*An ngx_http_phase_handler_t answer method is defined in the global ngx_http_phase_engine_t structure Array composed of. H p*and Phase_handler members are used in conjunction with the array. Indicates that the request should execute phase_handler next time as the callback method in the array specified by the sequence number */
- ngx_int_t The NGX_HTTP_CONTENT_PHASE phase provides a way for the http module to process requests. It points to the request processing method implemented by the http module
- ngx_http_handler_pt content_handler;
- //When the NGX_HTTP_ACCESS_PHASE node needs to determine whether the request has access permissions , pass access_code to pass the return of the handler callback method of the http module Value, if it is 0, it means it has permission. Otherwise it is not available.
- ngx_uint_t access_code;
- ngx_http_variable_value_t *variables;
- #if (NGX_PCRE)
- ngx_uint_t ncaptures;
- int*captures;
- u_char *captures_data;
- #endif
- size_tlimit_rate;
- /* used to learn the Apache compatible response length without a header */
- size_theader_size;
- //http请求的全部长度,包括http包体
- off_t request_length;
- ngx_uint_t err_status;
- ngx_http_connection_t *http_connection;
- #if (NGX_HTTP_SPDY)
- ngx_http_spdy_stream_t *spdy_stream;
- #endif
- ngx_http_log_handler_pt log_handler;
- //在这个请求中如果打开了某些资源,并需要在请求结束时释放,那么需要把定义的释放资源的方法添加到这个成员
- ngx_http_cleanup_t *cleanup;
- unsigned subrequests:8;
- //引用计数一般都作用于这个请求的原始请求上
- //引用计数,每当派生出子请求时,原始请求的count成员都会加一
- unsigned count:8;
- //阻塞标志位,目前仅由aio使用
N unsigned blocked: 8;
- // logo bit: 1 indicates that the egg white request is using asynchronous IO
unsigned AIO: 1;
unsigned http_state:4;
- /* URI with "/." and on Win32 with "//" */
unsigned complex_uri:1;
plus_in_uri:1;
- /* URI with " " space_in_uri:1;
- unsigned invalid_header:1;
- unsigned unsigned add_uri_to_alias:1;unsigned valid_location:1;
- unsigned unsigned valid_unparsed_uri:1;
- //Flag bit: When it is 1, it means that the URL has been rewritten
- N unsigned uri_changed: 1;
- // indicate the number of times using reWrite to rewrite the URL
UNSIGNED URI_CHANGES: 4;
- unsigned request_body_in_file_only:1;
- unsigned request_body_in_persistent_file:1;
- unsigned request_body_in_clean_file:1;
- unsigned request_body_file_group_access:1;
- unsigned request_body_file_log_level:3;
- unsigned subrequest_in_memory:1;
- unsigned waited:1;
- #if (NGX_HTTP_CACHE)
- unsigned cached:1;
- #endif
- #if (NGX_HTTP_GZIP)
- unsigned gzip_tested:1;
- unsigned gzip_ok:1;
- unsigned gzip_vary:1;
- #endif
- unsigned proxy:1;
- unsigned bypass_cache:1;
- unsigned no_cache:1;
- /*
- * instead of using the request context data in
- * ngx_http_limit_conn_module and ngx_http_limit_req_module
- * we use the single bits in the request structure
- */
- unsigned limit_conn_set:1;
- unsigned limit_req_set:1;
- #if 0
N unsigned cacheable: 1;
- #Endif
unsigned pipeline: 1;
unsigned chunked: 1;
unsigned header_only: 1;
- //Flag bit, 1 indicates a keepalive request during the current request
unsigned keepalive:1;
- //Delayed closing flag
unsigned lingering_close:1 ;
- //Flag bit: 1 indicates that the package body in the http request is being discarded
unsigned
//Flag bit: 1 indicates the requested current The status is doing an internal jump
- unsigned error_page:1;
- unsigned unsigned filter_finalize:1;
- unsigned post_action:1; request_output: 1;
- unsigned header_sent:1;
- unsigned expect_tested:1;
- unsigned root_tested:1;
- done:1;
- //Flag bit, indicating whether there is content to be sent in the buffer
- unsigned
- unsigned unsigned main_filter_need_in_memory:1;
- filter_need_in_memory:1;
- unsigned filter_need_temporary:1;
- unsigned allow_ranges:1; (NGX_STAT_STUB)
unsigned stat_reading:1;
unsigned stat_writing:1; */
//The state machine uses state to represent the current parsing status when parsing http. You need to check whether it constitutes a completed http request line
- ngx_uint_ t state;
- ngx_uint_t header_hash;
- ngx_uint_t lowcase_index;
- u_char u_char lowcase_header[NGX_HTTP_LC_HEADER_LEN];u_char *header_name_start;u_char ;
- /*
- * a memory that can be reused after parsing a request line
- * via ngx_http_ephemeral_t
- */
- u_char *uri_start;
- u_char *uri_end;
- u_char *uri_ext;
- u_char *args_start;
- u_char *request_start;
- u_char *request_end;
- u_char *method_end;
- u_char *schema_start;
- u_char *schema_end;
- u_char *host_start;
- u_char *host_end;
- u_char *port_start;
- u_char *port_end;
- unsigned http_minor:16;
- unsigned http_major:16;
- };
以上就介绍了 Nginx学习之三-ngx_http_request_t结构体,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。