Home Backend Development PHP Tutorial Nginx learning three-ngx_http_request_t structure

Nginx learning three-ngx_http_request_t structure

Jul 28, 2016 am 08:26 AM
http nbsp request

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 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1257
29
C# Tutorial
1232
24
Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

How to Hide and Unhide Folders on Windows 11 [3 Ways] How to Hide and Unhide Folders on Windows 11 [3 Ways] Sep 23, 2023 am 08:37 AM

Hiding folders is a great way to keep your desktop organized. Maybe you want to keep your personal files or some client details away from prying eyes. Whatever it is, the ability to put them away and unhide them when necessary is a big saver. In short, these hidden files will not show up in the main menu, but they will still be accessible. It's very simple and shouldn't take you too much time. How to hide a folder in Windows 11? 1. Use File Explorer and hit the + key to open File Explorer. WindowsE Find the folder you want to hide, right-click it and select Properties. Navigate to the General tab, check the Hide box, click Apply, and then click OK. In the next dialog box, check Apply changes to this folder, sub-folder

See all articles