Three-ngx_http_request_t structure of Nginx Learning

Source: Internet
Author: User
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?

  1. struct ngx_http_request_s {
  2. uint32_t signature; / * "HTTP" * /
  3. //Request the corresponding client connection
  4. Ngx_connection_t *connection;
  5. //pointer array to the context structure that holds all HTTP modules
  6. void **ctx;
  7. an array of pointers to the request corresponding to the body of the main level configuration structure
  8. void **main_conf;
  9. an array of pointers to the request corresponding to the configuration structure of the SRV level
  10. void **srv_conf;
  11. an array of pointers to the request corresponding to the LOC level configuration structure
  12. void **loc_conf;
  13. /*
  14. * 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.
  15. 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,
  16. 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.
  17. 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
  18. */
  19. Ngx_http_event_handler_pt Read_event_handler;
  20. //Similar to the method above
  21. Ngx_http_event_handler_pt Write_event_handler;
  22. #if (Ngx_http_cache)
  23. ngx_http_cache_t *cache;
  24. #endif
  25. structure used by the//upstream mechanism
  26. Ngx_http_upstream_t *upstream;
  27. ngx_array_t *upstream_states;
  28. / * of ngx_http_upstream_state_t * *
  29. //The memory pool for this request
  30. ngx_pool_t *pool;
  31. //buffer for receiving HTTP request content, primarily receiving HTTP headers
  32. ngx_buf_t *header_in;
  33. 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
  34. Ngx_http_headers_in_t headers_in;
  35. 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
  36. ngx_http_headers_out_t headers_out;
  37. //Receive the data structure of the package body in the request
  38. ngx_http_request_body_t *request_body;
  39. //Delay Closing the connection time
  40. time_t Lingering_time;
  41. //time when the current request was initialized
  42. time_t start_sec;
  43. ngx_msec_t start_msec;
  44. ////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
  45. Ngx_uint_t method; //Method name
  46. ngx_uint_t http_version; //Protocol version
  47. ngx_str_t Request_line;
  48. ngx_str_t URI; //URI in user request
  49. ngx_str_t args; //url parameter in user request
  50. ngx_str_t Exten; //user-requested file name extension
  51. ngx_str_t Unparsed_uri; //The original request without URL decoding
  52. ngx_str_t method_name; //Method name string in user request
  53. ngx_str_t Http_protocol; //Its data member points to the HTTP start address in the request
  54. / * 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.
  55. * 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. */
  56. Ngx_chain_t *out;
  57. / * The current request may be either a request from the user or a derived child request.
  58. * While main identifies a series of related derived child requests for the original request.
  59. * 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. */
  60. ngx_http_request_t *main;
  61. //The parent request of the current request (not necessarily the original request)
  62. ngx_http_request_t *parent;
  63. //functions related to Subrequest sub-requests
  64. ngx_http_postponed_request_t *postponed;
  65. ngx_http_post_subrequest_t *post_subrequest;
  66. //All sub-requests are connected by this single chain.
  67. ngx_http_posted_request_t *posted_requests;
  68. / * An array of ngx_http_phase_handler_t answer methods is defined in the global ngx_http_phase_engine_t structure.
  69. * 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 * /
  70. ngx_int_t Phase_handler;
  71. //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
  72. Ngx_http_handler_pt Content_handler;
  73. //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.
  74. ngx_uint_t Access_code;
  75. ngx_http_variable_value_t *variables;
  76. #if (ngx_pcre)
  77. ngx_uint_t Ncaptures;
  78. int *captures;
  79. U_char *captures_data;
  80. #endif
  81. size_t limit_rate;
  82. / * Used to learn the Apache compatible response length without a header * /
  83. size_t header_size;
  84. the full length of the//http request, including the HTTP package body
  85. off_t request_length;
  86. ngx_uint_t Err_status;
  87. Ngx_http_connection_t *http_connection;
  88. #if (ngx_http_spdy)
  89. Ngx_http_spdy_stream_t *spdy_stream;
  90. #endif
  91. Ngx_http_log_handler_pt Log_handler;
  92. 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
  93. ngx_http_cleanup_t *cleanup;
  94. unsigned subrequests:8;
  95. The //reference count is generally used on the original request for this request
  96. //reference count, each time a child request is derived, the count member of the original request adds a
  97. unsigned count:8;
  98. //Blocking flag, currently used only by AIO
  99. unsigned blocked:8;
  100. //Flag 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. / * URI with "%" * /
  106. unsigned quoted_uri:1;
  107. / * URI with "+" * /
  108. unsigned plus_in_uri:1;
  109. / * URI with "" * /
  110. unsigned space_in_uri:1;
  111. unsigned invalid_header:1;
  112. unsigned add_uri_to_alias:1;
  113. unsigned valid_location:1;
  114. unsigned valid_unparsed_uri:1;
  115. //Flag bit: 1 indicates URL has occurred rewrite override
  116. unsigned uri_changed:1;
  117. //Indicates the number of times the URL was rewritten with rewrite
  118. unsigned uri_changes:4;
  119. unsigned request_body_in_single_buf:1;
  120. unsigned request_body_in_file_only:1;
  121. unsigned request_body_in_persistent_file:1;
  122. unsigned request_body_in_clean_file:1;
  123. unsigned request_body_file_group_access:1;
  124. unsigned request_body_file_log_level:3;
  125. unsigned subrequest_in_memory:1;
  126. unsigned waited:1;
  127. #if (Ngx_http_cache)
  128. unsigned cached:1;
  129. #endif
  130. #if (ngx_http_gzip)
  131. unsigned gzip_tested:1;
  132. unsigned gzip_ok:1;
  133. unsigned gzip_vary:1;
  134. #endif
  135. unsigned proxy:1;
  136. unsigned bypass_cache:1;
  137. unsigned no_cache:1;
  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. #if 0
  146. unsigned cacheable:1;
  147. #endif
  148. unsigned pipeline:1;
  149. unsigned chunked:1;
  150. unsigned header_only:1;
  151. //Flag bit, 1 represents the current request when the KeepAlive request
  152. unsigned keepalive:1;
  153. //Delay off flag bit
  154. unsigned lingering_close:1;
  155. //Flag bit: 1 indicates that the package body in the HTTP request is being discarded
  156. unsigned discard_body:1;
  157. //Flag bit: 1 indicates that the current state of the request is doing an internal jump
  158. unsigned internal:1;
  159. unsigned error_page:1;
  160. unsigned ignore_content_encoding:1;
  161. unsigned filter_finalize:1;
  162. unsigned post_action:1;
  163. unsigned request_complete:1;
  164. unsigned request_output:1;
  165. //Flag bit: 1 indicates that the HTTP response header that occurred to the client has been sent
  166. unsigned header_sent:1;
  167. unsigned expect_tested:1;
  168. unsigned root_tested:1;
  169. unsigned done:1;
  170. unsigned logged:1;
  171. //flag to indicate if content is to be sent in the buffer
  172. unsigned buffered:4;
  173. unsigned main_filter_need_in_memory:1;
  174. unsigned filter_need_in_memory:1;
  175. unsigned filter_need_temporary:1;
  176. unsigned allow_ranges:1;
  177. #if (ngx_stat_stub)
  178. unsigned stat_reading:1;
  179. unsigned stat_writing:1;
  180. #endif
  181. / * Used to parse HTTP headers * /
  182. //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
  183. ngx_uint_t State;
  184. ngx_uint_t Header_hash;
  185. ngx_uint_t Lowcase_index;
  186. U_char Lowcase_header[ngx_http_lc_header_len];
  187. U_char *header_name_start;
  188. U_char *header_name_end;
  189. U_char *header_start;
  190. U_char *header_end;
  191. /*
  192. * A memory that can is reused after parsing a request line
  193. * via ngx_http_ephemeral_t
  194. */
  195. U_char *uri_start;
  196. U_char *uri_end;
  197. U_char *uri_ext;
  198. U_char *args_start;
  199. U_char *request_start;
  200. U_char *request_end;
  201. U_char *method_end;
  202. U_char *schema_start;
  203. U_char *schema_end;
  204. U_char *host_start;
  205. U_char *host_end;
  206. U_char *port_start;
  207. U_char *port_end;
  208. unsigned http_minor:16;
  209. unsigned http_major:16;
  210. };

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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.