Home >Backend Development >PHP Tutorial >Nginx learning three-ngx_http_request_t structure

Nginx learning three-ngx_http_request_t structure

WBOY
WBOYOriginal
2016-07-28 08:26:281041browse

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 plain copy print?

  1. structngx_http_request_s {
  2. uint32_t signature; /* "HTTP" */
  3. //Request the corresponding client connection
  4. ngx_connection_t *connection;
  5. //Array of pointers to context structures that store all HTTP modules
  6.                                                                            //Array of pointers pointing to the main level configuration structure corresponding to the request
  7. void **main_conf;
  8. //Pointer to the srv level configuration structure corresponding to the request Array
  9. void                                                       Pointer array of loc level configuration structure
  10. void loc_conf;
  11. /*
  12. 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,
  13. 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.
  14. 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
  15. */
  16. ngx _http_event_handler_pt                                  read_event_handler;                                          /Similar to the above method
  17. ngx_http_event_handler_pt write_event_handler;
  18. #if (NGX_HTTP_CACHE)
  19. ngx_http_cache_t *cache;
  20. #endif
  21. /
  22. // The structure used by the upstream mechanism ngx_http_upstream_t*upstream; ngx_array_t*upstream_states;
  23. *pool;
  24. //Buffer used to receive http request content, mainly receiving http headers Department
  25. ngx_buf_t *header_in;
  26. 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
  27. ngx_http_headers_in_t headers_in;
  28. //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
  29. ngx_http_headers_out_t headers_out;
  30. //Receive request The data structure of the body
  31. ngx_http_request_body_t * Request_body;
  32. // Delaying the time to close the connection
  33. Time_t
  34. lingering_time;
  35. // The current request initialization time
  36.                                                                                                                                                 
  37. //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
  38. ngx_uint_t ngx_uint_t method; //Method name
  39. ngx_uint_t http_version ; 议 // Protocol version
  40. ngx_str_t request_line;
  41. ngx_str_t uri; // Uri
  42. ngx_str_t args in the user request; // User request request The url parameter in the middle
  43. ngx_str_t exten;
  44. // The file requested by the user expansion name ngx_str_t unparsed_uri; // The original request without URL decoding
  45. ngx_str_t ngx_str_t method_name;//Method name string in user request
  46. ngx_str_t                    http_protocol;//The data member points to the http starting address in the request
  47.                                                                                          /* 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.
  48. * 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. */
  49. ngx_chain_t *out;
  50. /*The current request may be a request sent by the user or a derived sub-request.
  51. * 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.*/
  52. ngx_http_request_t *main;
  53. //The parent request of the current request (not necessarily the original request)
  54. ngx_http_request_t *parent;
  55. // Functions related to subrequest sub-requests
  56. ngx_http_postponed_request_t *postponed;
  57. ngx_http_post_subrequest_t *post_subrequest;
  58. //All sub-requests are linked through this singly linked list
  59. ngx_http_posted_request_t *posted_requests;
  60. /*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 */
  61. 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
  62. ngx_http_handler_pt content_handler;
  63. //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.  
  64.     ngx_uint_t                        access_code;  
  65.   
  66.     ngx_http_variable_value_t        *variables;  
  67.   
  68. #if (NGX_PCRE)  
  69.     ngx_uint_t                        ncaptures;  
  70.     int                              *captures;  
  71.     u_char                           *captures_data;  
  72. #endif  
  73.   
  74.     size_t                            limit_rate;  
  75.   
  76.     /* used to learn the Apache compatible response length without a header */  
  77.     size_t                            header_size;  
  78.   
  79.     //http请求的全部长度,包括http包体  
  80.     off_t                             request_length;  
  81.   
  82.     ngx_uint_t                        err_status;  
  83.   
  84.     ngx_http_connection_t            *http_connection;  
  85. #if (NGX_HTTP_SPDY)  
  86.     ngx_http_spdy_stream_t           *spdy_stream;  
  87. #endif  
  88.   
  89.     ngx_http_log_handler_pt           log_handler;  
  90.   
  91.     //在这个请求中如果打开了某些资源,并需要在请求结束时释放,那么需要把定义的释放资源的方法添加到这个成员  
  92.     ngx_http_cleanup_t               *cleanup;  
  93.   
  94.     unsigned                          subrequests:8;  
  95.     //引用计数一般都作用于这个请求的原始请求上  
  96.     //引用计数,每当派生出子请求时,原始请求的count成员都会加一  
  97.     unsigned                          count:8;  
  98.     //阻塞标志位,目前仅由aio使用  
  99. N unsigned blocked: 8;
  100. // logo bit: 1 indicates that the egg white request is using asynchronous IO
  101. unsigned AIO: 1;
  102. unsigned http_state:4;
  103. /* URI with "/." and on Win32 with "//" */
  104. unsigned complex_uri:1;
  105.                                                                                                                          
  106.                                                                                                                                                                             plus_in_uri:1;
  107. /* URI with " " space_in_uri:1;
  108. unsigned invalid_header:1;
  109. unsigned unsigned add_uri_to_alias:1; unsigned valid_location:1;
  110. unsigned unsigned valid_unparsed_uri:1;
  111. //Flag bit: When it is 1, it means that the URL has been rewritten
  112. N unsigned uri_changed: 1;
  113. // indicate the number of times using reWrite to rewrite the URL
  114. UNSIGNED URI_CHANGES: 4;
  115. unsigned request_body_in_file_only:1;
  116.     unsigned                          request_body_in_persistent_file:1;  
  117.     unsigned                          request_body_in_clean_file:1;  
  118.     unsigned                          request_body_file_group_access:1;  
  119.     unsigned                          request_body_file_log_level:3;  
  120.   
  121.     unsigned                          subrequest_in_memory:1;  
  122.     unsigned                          waited:1;  
  123.   
  124. #if (NGX_HTTP_CACHE)  
  125.     unsigned                          cached:1;  
  126. #endif  
  127.   
  128. #if (NGX_HTTP_GZIP)  
  129.     unsigned                          gzip_tested:1;  
  130.     unsigned                          gzip_ok:1;  
  131.     unsigned                          gzip_vary:1;  
  132. #endif  
  133.   
  134.     unsigned                          proxy:1;  
  135.     unsigned                          bypass_cache:1;  
  136.     unsigned                          no_cache:1;  
  137.   
  138.     /* 
  139.      * instead of using the request context data in 
  140.      * ngx_http_limit_conn_module and ngx_http_limit_req_module 
  141.      * we use the single bits in the request structure 
  142.      */  
  143.     unsigned                          limit_conn_set:1;  
  144.     unsigned                          limit_req_set:1;  
  145.   
  146. #if 0  
  147. N unsigned cacheable: 1;
  148. #Endif
  149. unsigned pipeline: 1;
  150. unsigned chunked: 1;
  151. unsigned header_only: 1;
  152. //Flag bit, 1 indicates a keepalive request during the current request
  153. unsigned keepalive:1;
  154. //Delayed closing flag
  155. unsigned lingering_close:1 ;
  156. //Flag bit: 1 indicates that the package body in the http request is being discarded
  157. unsigned                                                      
  158. //Flag bit: 1 indicates the requested current The status is doing an internal jump
  159. unsigned                                     error_page:1;
  160. unsigned unsigned filter_finalize:1;
  161. unsigned                                  post_action:1;                   request_output: 1;                                                                                                                                                                                                    
  162.  unsigned header_sent:1;
  163. unsigned expect_tested:1;
  164. unsigned root_tested:1;
  165.                                                                                                                                                                                                                                       done:1;
  166. //Flag bit, indicating whether there is content to be sent in the buffer
  167. unsigned
  168. unsigned unsigned main_filter_need_in_memory:1;
  169. filter_need_in_memory:1;
  170. unsigned filter_need_temporary:1;
  171. unsigned                           allow_ranges:1; (NGX_STAT_STUB)
  172. unsigned stat_reading:1;
  173. unsigned          stat_writing:1;                                                                      */
  174. //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
  175. ngx_uint_ t                                                                          state;
  176. ngx_uint_t header_hash;
  177. ngx_uint_t lowcase_index;
  178. u_char u_char lowcase_header[NGX_HTTP_LC_HEADER_LEN]; u_char                                         *header_name_start;       u_char                                                                                                           ;
  179.     /* 
  180.      * a memory that can be reused after parsing a request line 
  181.      * via ngx_http_ephemeral_t 
  182.      */  
  183.   
  184.     u_char                           *uri_start;  
  185.     u_char                           *uri_end;  
  186.     u_char                           *uri_ext;  
  187.     u_char                           *args_start;  
  188.     u_char                           *request_start;  
  189.     u_char                           *request_end;  
  190.     u_char                           *method_end;  
  191.     u_char                           *schema_start;  
  192.     u_char                           *schema_end;  
  193.     u_char                           *host_start;  
  194.     u_char                           *host_end;  
  195.     u_char                           *port_start;  
  196.     u_char                           *port_end;  
  197.   
  198.     unsigned                          http_minor:16;  
  199.     unsigned                          http_major:16;  
  200. }; 

以上就介绍了 Nginx学习之三-ngx_http_request_t结构体,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn