Excerpt from: http://blog.csdn.net/xiajun07061225/article/details/9189505 Jiangyu Cloud Blog
Ngx_http_request_s is a very important structure in nginx, which is used throughout the process of HTPP request processing.
The following explains the important member variables in the ngx_http_request_s structure that are related to the HTTP framework.
[CPP] View plain copy print?
- struct ngx_http_request_s {
- uint32_t signature; / * "HTTP" * /
- //Request the corresponding client connection
- Ngx_connection_t *connection;
- //pointer array to the context structure that holds all HTTP modules
- void **ctx;
- an array of pointers to the request corresponding to the body of the main level configuration structure
- void **main_conf;
- an array of pointers to the request corresponding to the configuration structure of the SRV level
- void **srv_conf;
- an array of pointers to the request corresponding to the LOC level configuration structure
- void **loc_conf;
- /*
- * The HTTP framework provides the processing method for the first time the HTTP request is processed on the business, after receiving the HTTP header ngx_http_process_request.
- However, if the method cannot process the entire business of the request at one time, after the return of control to the Epoll time module, the request is again recalled,
- will be handled by the Ngx_http_request_handler method, and the processing of the readable event in this method is to call Read_event_handler to process the request.
- in other words, the HTTP module wants to re-implement the Read_event_handler method when it processes the read event of the request at the bottom
- */
- Ngx_http_event_handler_pt Read_event_handler;
- //Similar to the method above
- Ngx_http_event_handler_pt Write_event_handler;
- #if (Ngx_http_cache)
- ngx_http_cache_t *cache;
- #endif
- structure used by the//upstream mechanism
- Ngx_http_upstream_t *upstream;
- ngx_array_t *upstream_states;
- / * of ngx_http_upstream_state_t * *
- //The memory pool for this request
- ngx_pool_t *pool;
- //buffer for receiving HTTP request content, primarily receiving HTTP headers
- ngx_buf_t *header_in;
- after receiving and parsing the HTTP request header,//ngx_http_process_request_headers will add each HTTP header parsed to the HEADERS_IN headers linked list, and will construct Headers_ Other members in
- Ngx_http_headers_in_t headers_in;
- The //http module puts the HTTP corresponding information you want to send into headers_out, expecting the HTTP framework to serialize the members in the Headers_out to the HTTP response packets to the user
- ngx_http_headers_out_t headers_out;
- //Receive the data structure of the package body in the request
- ngx_http_request_body_t *request_body;
- //Delay Closing the connection time
- time_t Lingering_time;
- //time when the current request was initialized
- time_t start_sec;
- ngx_msec_t start_msec;
- ////The following 9 members are the function Ngx_http_process_request_line methods to parse out the information when the HTTP request line is received and resolved
- Ngx_uint_t method; //Method name
- ngx_uint_t http_version; //Protocol version
- ngx_str_t Request_line;
- ngx_str_t URI; //URI in user request
- ngx_str_t args; //url parameter in user request
- ngx_str_t Exten; //user-requested file name extension
- ngx_str_t Unparsed_uri; //The original request without URL decoding
- ngx_str_t method_name; //Method name string in user request
- ngx_str_t Http_protocol; //Its data member points to the HTTP start address in the request
- / * Indicates the HTTP response that needs to be sent to the client. A TCP stream that is serialized in Headers_out that represents the HTTP header is stored in out.
- * After calling the Ngx_http_output_filter method, the outgoing HTTP packet is also stored in out, which is the key to implementing the HTTP response asynchronously. */
- Ngx_chain_t *out;
- / * The current request may be either a request from the user or a derived child request.
- * While main identifies a series of related derived child requests for the original request.
- * It is generally possible to determine whether the current request is the original request from the user through the equality of the address of main and the current request. */
- 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 connected by this single chain.
- ngx_http_posted_request_t *posted_requests;
- / * An array of ngx_http_phase_handler_t answer methods is defined in the global ngx_http_phase_engine_t structure.
- * The Phase_handler member is used in conjunction with the array. Represents the callback method in the array specified by the Phase_handler as the next time the request should be executed * /
- ngx_int_t Phase_handler;
- //Represents a way for the HTTP module to process the request in the ngx_http_content_phase phase, which points to the request handling method implemented by the HTTP module
- Ngx_http_handler_pt Content_handler;
- //The return value of the HTTP module's handler callback method is passed through Access_code when the Ngx_http_access_phase node needs to determine whether the request has access, if 0 is the permission. otherwise not.
- 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_t limit_rate;
- / * Used to learn the Apache compatible response length without a header * /
- size_t header_size;
- the full length of the//http request, including the HTTP package body
- 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;
- If some resources are opened in this request and need to be released at the end of the request, then the defined method of freeing the resource needs to be added to this member
- ngx_http_cleanup_t *cleanup;
- unsigned subrequests:8;
- The //reference count is generally used on the original request for this request
- //reference count, each time a child request is derived, the count member of the original request adds a
- unsigned count:8;
- //Blocking flag, currently used only by AIO
- unsigned blocked:8;
- //Flag 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;
- / * URI with "%" * /
- unsigned quoted_uri:1;
- / * URI with "+" * /
- unsigned plus_in_uri:1;
- / * URI with "" * /
- unsigned space_in_uri:1;
- unsigned invalid_header:1;
- unsigned add_uri_to_alias:1;
- unsigned valid_location:1;
- unsigned valid_unparsed_uri:1;
- //Flag bit: 1 indicates URL has occurred rewrite override
- unsigned uri_changed:1;
- //Indicates the number of times the URL was rewritten with rewrite
- unsigned uri_changes:4;
- unsigned request_body_in_single_buf:1;
- 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
- unsigned cacheable:1;
- #endif
- unsigned pipeline:1;
- unsigned chunked:1;
- unsigned header_only:1;
- //Flag bit, 1 represents the current request when the KeepAlive request
- unsigned keepalive:1;
- //Delay off flag bit
- unsigned lingering_close:1;
- //Flag bit: 1 indicates that the package body in the HTTP request is being discarded
- unsigned discard_body:1;
- //Flag bit: 1 indicates that the current state of the request is doing an internal jump
- unsigned internal:1;
- unsigned error_page:1;
- unsigned ignore_content_encoding:1;
- unsigned filter_finalize:1;
- unsigned post_action:1;
- unsigned request_complete:1;
- unsigned request_output:1;
- //Flag bit: 1 indicates that the HTTP response header that occurred to the client has been sent
- unsigned header_sent:1;
- unsigned expect_tested:1;
- unsigned root_tested:1;
- unsigned done:1;
- unsigned logged:1;
- //flag to indicate if content is to be sent in the buffer
- unsigned buffered:4;
- unsigned main_filter_need_in_memory:1;
- unsigned filter_need_in_memory:1;
- unsigned filter_need_temporary:1;
- unsigned allow_ranges:1;
- #if (ngx_stat_stub)
- unsigned stat_reading:1;
- unsigned stat_writing:1;
- #endif
- / * Used to parse HTTP headers * /
- //State machine to resolve HTTP by using the state to represent the current resolution status, you need to check whether the completed HTTP request line is formed
- ngx_uint_t State;
- ngx_uint_t Header_hash;
- ngx_uint_t Lowcase_index;
- U_char Lowcase_header[ngx_http_lc_header_len];
- U_char *header_name_start;
- U_char *header_name_end;
- U_char *header_start;
- U_char *header_end;
- /*
- * A memory that can is 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;
- };
The above describes the Nginx learning three-ngx_http_request_t structure, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.