Nginx learning three-ngx_http_request_t structure

WBOY
Release: 2016-07-28 08:26:28
Original
966 people have browsed it

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?

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

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!