nginx的ngx_http_request_t結構體

struct ngx_http_request_s {  
    uint32_t                          signature;         /* "HTTP" */  
  
    //請求對應的客戶端鏈接  
    ngx_connection_t                 *connection;  
  
    //指向存放全部HTTP模塊的上下文結構體的指針數組  
    void                            **ctx;  
    //指向請求對應的存放main級別配置結構體的指針數組  
    void                            **main_conf;  
    //指向請求對應的存放srv級別配置結構體的指針數組  
    void                            **srv_conf;  
    //指向請求對應的存放loc級別配置結構體的指針數組  
    void                            **loc_conf;  
  
    /* 
     * 在接收完http頭部,第一次在業務上處理http請求時,http框架提供的處理方法是ngx_http_process_request。 
     但若是該方法沒法一次處理完該請求的所有業務,在歸還控制權到epoll時間模塊後,該請求再次被回調時, 
     將經過Ngx_http_request_handler方法來處理,而這個方法中對於可讀事件的處理就是調用read_event_handler處理請求。 
     也就是說,http模塊但願在底層處理請求的讀事件時,從新實現read_event_handler方法 
    */  
    ngx_http_event_handler_pt         read_event_handler;  
    //與上面的方法相似  
    ngx_http_event_handler_pt         write_event_handler;  
  
#if (NGX_HTTP_CACHE)  
    ngx_http_cache_t                 *cache;  
#endif  
  
    //upstream機制用到的結構體  
    ngx_http_upstream_t              *upstream;  
    ngx_array_t                      *upstream_states;  
                                         /* of ngx_http_upstream_state_t */  
  
    //這個請求的內存池  
    ngx_pool_t                       *pool;  
    //用於接收http請求內容的緩衝區,主要接收http頭部  
    ngx_buf_t                        *header_in;  
  
    //ngx_http_process_request_headers在接收、解析完http請求的頭部後,會把解析完的每個http頭部加入到headers_in的headers鏈表中,同時會構造headers_in中的其餘成員  
    ngx_http_headers_in_t             headers_in;  
    //http模塊會把想要發送的http相應信息放到headers_out中,指望http框架將headers_out中的成員序列化爲http響應包發送給用戶  
    ngx_http_headers_out_t            headers_out;  
  
    //接收請求中包體的數據結構  
    ngx_http_request_body_t          *request_body;  
  
    //延遲關閉鏈接的時間  
    time_t                            lingering_time;  
    //當前請求初始化時的時間  
    time_t                            start_sec;  
    ngx_msec_t                        start_msec;  
  
    //下面的9個成員是函數ngx_http_process_request_line方法在接收、解析http請求行時解析出的信息  
    ngx_uint_t                        method;//方法名  
    ngx_uint_t                        http_version;//協議版本  
  
    ngx_str_t                         request_line;  
    ngx_str_t                         uri;//用戶請求中的uri  
    ngx_str_t                         args;//用戶請求中的url參數  
    ngx_str_t                         exten;//用戶請求的文件擴展名  
    ngx_str_t                         unparsed_uri;//沒有進行URL解碼的原始請求  
  
    ngx_str_t                         method_name;//用戶請求中的方法名字符串  
    ngx_str_t                         http_protocol;//其data成員指向請求中http起始地址  
  
    /*表示須要發送給客戶端的http響應。out中保存着由headers_out中序列化後的表示http頭部的TCP流。 
     * 在調用ngx_http_output_filter方法後,out中還會保存着待發送的http包體,它是實現異步發送http響應的關鍵。*/  
    ngx_chain_t                      *out;  
    /*當前請求既有多是用戶發來的請求,也多是派生出的子請求。 
     * 而main標識一系列相關的派生子請求的原始請求。 
     * 通常可經過main和當前請求的地址是否相等來判斷當前請求是否爲用戶發來的原始請求。*/  
    ngx_http_request_t               *main;  
    //當前請求的父請求(不必定是原始請求)  
    ngx_http_request_t               *parent;  
    //與subrequest子請求相關的功能  
    ngx_http_postponed_request_t     *postponed;  
    ngx_http_post_subrequest_t       *post_subrequest;  
    //全部的子請求都是經過這個單鏈表連接起來的  
    ngx_http_posted_request_t        *posted_requests;  
  
    /*全局的ngx_http_phase_engine_t結構體中定義了一個ngx_http_phase_handler_t回答方法組成的數組。 
     * 而phase_handler成員則與該數組配合使用。表示請求下次應當執行phase_handler做爲序列號指定的數組中的回調方法*/  
    ngx_int_t                         phase_handler;  
    //表示NGX_HTTP_CONTENT_PHASE階段提供給http模塊處理請求的一種方式,它指向http模塊實現的請求處理方法  
    ngx_http_handler_pt               content_handler;  
    //在NGX_HTTP_ACCESS_PHASE節點須要判斷請求是否具備訪問權限時,經過access_code來傳遞http模塊的handler回調方法的返回值,若是爲0表示具有權限。不然不具有。  
    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;  
  
    //http請求的所有長度,包括http包體  
    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;  
  
    //在這個請求中若是打開了某些資源,並須要在請求結束時釋放,那麼須要把定義的釋放資源的方法添加到這個成員  
    ngx_http_cleanup_t               *cleanup;  
  
    unsigned                          subrequests:8;  
    //引用計數通常都做用於這個請求的原始請求上  
    //引用計數,每當派生出子請求時,原始請求的count成員都會加一  
    unsigned                          count:8;  
    //阻塞標誌位,目前僅由aio使用  
    unsigned                          blocked:8;  
  
    //標誌位:爲1表示蛋清請求正在使用異步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;  
    //標誌位:爲1時表示URL發生過rewrite重寫  
    unsigned                          uri_changed:1;  
    //表示使用rewrite重寫URL的次數  
    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;  
    //標誌位,爲1表示當前請求時keepalive請求  
    unsigned                          keepalive:1;  
    //延遲關閉標誌位  
    unsigned                          lingering_close:1;  
    //標誌位:爲1表示正在丟棄http請求中的包體  
    unsigned                          discard_body:1;  
    //標誌位:爲1表示請求的當前狀態是在作內部跳轉  
    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;  
    //標誌位:爲1表示發生給客戶端的http響應頭已經發送  
    unsigned                          header_sent:1;  
    unsigned                          expect_tested:1;  
    unsigned                          root_tested:1;  
    unsigned                          done:1;  
    unsigned                          logged:1;  
  
    //標誌位,表示緩衝中是否有待發送內容  
    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 */  
  
    //狀態機解析http時使用state來表示當前的解析狀態,須要檢查是否構成完成的http請求行  
    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 be 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;  
};  

 

轉http://blog.csdn.net/xiajun07061225/article/details/9189505 數組

  1. struct ngx_http_request_s {  
  2.     uint32_t                          signature;         /* "HTTP" */  
  3.   
  4.     //請求對應的客戶端鏈接  
  5.     ngx_connection_t                 *connection;  
  6.   
  7.     //指向存放全部HTTP模塊的上下文結構體的指針數組  
  8.     void                            **ctx;  
  9.     //指向請求對應的存放main級別配置結構體的指針數組  
  10.     void                            **main_conf;  
  11.     //指向請求對應的存放srv級別配置結構體的指針數組  
  12.     void                            **srv_conf;  
  13.     //指向請求對應的存放loc級別配置結構體的指針數組  
  14.     void                            **loc_conf;  
  15.   
  16.     /* 
  17.      * 在接收完http頭部,第一次在業務上處理http請求時,http框架提供的處理方法是ngx_http_process_request。 
  18.      但若是該方法沒法一次處理完該請求的所有業務,在歸還控制權到epoll時間模塊後,該請求再次被回調時, 
  19.      將經過Ngx_http_request_handler方法來處理,而這個方法中對於可讀事件的處理就是調用read_event_handler處理請求。 
  20.      也就是說,http模塊但願在底層處理請求的讀事件時,從新實現read_event_handler方法 
  21.     */  
  22.     ngx_http_event_handler_pt         read_event_handler;  
  23.     //與上面的方法相似  
  24.     ngx_http_event_handler_pt         write_event_handler;  
  25.   
  26. #if (NGX_HTTP_CACHE)  
  27.     ngx_http_cache_t                 *cache;  
  28. #endif  
  29.   
  30.     //upstream機制用到的結構體  
  31.     ngx_http_upstream_t              *upstream;  
  32.     ngx_array_t                      *upstream_states;  
  33.                                          /* of ngx_http_upstream_state_t */  
  34.   
  35.     //這個請求的內存池  
  36.     ngx_pool_t                       *pool;  
  37.     //用於接收http請求內容的緩衝區,主要接收http頭部  
  38.     ngx_buf_t                        *header_in;  
  39.   
  40.     //ngx_http_process_request_headers在接收、解析完http請求的頭部後,會把解析完的每個http頭部加入到headers_in的headers鏈表中,同時會構造headers_in中的其餘成員  
  41.     ngx_http_headers_in_t             headers_in;  
  42.     //http模塊會把想要發送的http相應信息放到headers_out中,指望http框架將headers_out中的成員序列化爲http響應包發送給用戶  
  43.     ngx_http_headers_out_t            headers_out;  
  44.   
  45.     //接收請求中包體的數據結構  
  46.     ngx_http_request_body_t          *request_body;  
  47.   
  48.     //延遲關閉鏈接的時間  
  49.     time_t                            lingering_time;  
  50.     //當前請求初始化時的時間  
  51.     time_t                            start_sec;  
  52.     ngx_msec_t                        start_msec;  
  53.   
  54.     //下面的9個成員是函數ngx_http_process_request_line方法在接收、解析http請求行時解析出的信息  
  55.     ngx_uint_t                        method;//方法名  
  56.     ngx_uint_t                        http_version;//協議版本  
  57.   
  58.     ngx_str_t                         request_line;  
  59.     ngx_str_t                         uri;//用戶請求中的uri  
  60.     ngx_str_t                         args;//用戶請求中的url參數  
  61.     ngx_str_t                         exten;//用戶請求的文件擴展名  
  62.     ngx_str_t                         unparsed_uri;//沒有進行URL解碼的原始請求  
  63.   
  64.     ngx_str_t                         method_name;//用戶請求中的方法名字符串  
  65.     ngx_str_t                         http_protocol;//其data成員指向請求中http起始地址  
  66.   
  67.     /*表示須要發送給客戶端的http響應。out中保存着由headers_out中序列化後的表示http頭部的TCP流。 
  68.      * 在調用ngx_http_output_filter方法後,out中還會保存着待發送的http包體,它是實現異步發送http響應的關鍵。*/  
  69.     ngx_chain_t                      *out;  
  70.     /*當前請求既有多是用戶發來的請求,也多是派生出的子請求。 
  71.      * 而main標識一系列相關的派生子請求的原始請求。 
  72.      * 通常可經過main和當前請求的地址是否相等來判斷當前請求是否爲用戶發來的原始請求。*/  
  73.     ngx_http_request_t               *main;  
  74.     //當前請求的父請求(不必定是原始請求)  
  75.     ngx_http_request_t               *parent;  
  76.     //與subrequest子請求相關的功能  
  77.     ngx_http_postponed_request_t     *postponed;  
  78.     ngx_http_post_subrequest_t       *post_subrequest;  
  79.     //全部的子請求都是經過這個單鏈表連接起來的  
  80.     ngx_http_posted_request_t        *posted_requests;  
  81.   
  82.     /*全局的ngx_http_phase_engine_t結構體中定義了一個ngx_http_phase_handler_t回答方法組成的數組。 
  83.      * 而phase_handler成員則與該數組配合使用。表示請求下次應當執行phase_handler做爲序列號指定的數組中的回調方法*/  
  84.     ngx_int_t                         phase_handler;  
  85.     //表示NGX_HTTP_CONTENT_PHASE階段提供給http模塊處理請求的一種方式,它指向http模塊實現的請求處理方法  
  86.     ngx_http_handler_pt               content_handler;  
  87.     //在NGX_HTTP_ACCESS_PHASE節點須要判斷請求是否具備訪問權限時,經過access_code來傳遞http模塊的handler回調方法的返回值,若是爲0表示具有權限。不然不具有。  
  88.     ngx_uint_t                        access_code;  
  89.   
  90.     ngx_http_variable_value_t        *variables;  
  91.   
  92. #if (NGX_PCRE)  
  93.     ngx_uint_t                        ncaptures;  
  94.     int                              *captures;  
  95.     u_char                           *captures_data;  
  96. #endif  
  97.   
  98.     size_t                            limit_rate;  
  99.   
  100.     /* used to learn the Apache compatible response length without a header */  
  101.     size_t                            header_size;  
  102.   
  103.     //http請求的所有長度,包括http包體  
  104.     off_t                             request_length;  
  105.   
  106.     ngx_uint_t                        err_status;  
  107.   
  108.     ngx_http_connection_t            *http_connection;  
  109. #if (NGX_HTTP_SPDY)  
  110.     ngx_http_spdy_stream_t           *spdy_stream;  
  111. #endif  
  112.   
  113.     ngx_http_log_handler_pt           log_handler;  
  114.   
  115.     //在這個請求中若是打開了某些資源,並須要在請求結束時釋放,那麼須要把定義的釋放資源的方法添加到這個成員  
  116.     ngx_http_cleanup_t               *cleanup;  
  117.   
  118.     unsigned                          subrequests:8;  
  119.     //引用計數通常都做用於這個請求的原始請求上  
  120.     //引用計數,每當派生出子請求時,原始請求的count成員都會加一  
  121.     unsigned                          count:8;  
  122.     //阻塞標誌位,目前僅由aio使用  
  123.     unsigned                          blocked:8;  
  124.   
  125.     //標誌位:爲1表示蛋清請求正在使用異步IO  
  126.     unsigned                          aio:1;  
  127.   
  128.     unsigned                          http_state:4;  
  129.   
  130.     /* URI with "/." and on Win32 with "//" */  
  131.     unsigned                          complex_uri:1;  
  132.   
  133.     /* URI with "%" */  
  134.     unsigned                          quoted_uri:1;  
  135.   
  136.     /* URI with "+" */  
  137.     unsigned                          plus_in_uri:1;  
  138.   
  139.     /* URI with " " */  
  140.     unsigned                          space_in_uri:1;  
  141.   
  142.     unsigned                          invalid_header:1;  
  143.   
  144.     unsigned                          add_uri_to_alias:1;  
  145.     unsigned                          valid_location:1;  
  146.     unsigned                          valid_unparsed_uri:1;  
  147.     //標誌位:爲1時表示URL發生過rewrite重寫  
  148.     unsigned                          uri_changed:1;  
  149.     //表示使用rewrite重寫URL的次數  
  150.     unsigned                          uri_changes:4;  
  151.   
  152.     unsigned                          request_body_in_single_buf:1;  
  153.     unsigned                          request_body_in_file_only:1;  
  154.     unsigned                          request_body_in_persistent_file:1;  
  155.     unsigned                          request_body_in_clean_file:1;  
  156.     unsigned                          request_body_file_group_access:1;  
  157.     unsigned                          request_body_file_log_level:3;  
  158.   
  159.     unsigned                          subrequest_in_memory:1;  
  160.     unsigned                          waited:1;  
  161.   
  162. #if (NGX_HTTP_CACHE)  
  163.     unsigned                          cached:1;  
  164. #endif  
  165.   
  166. #if (NGX_HTTP_GZIP)  
  167.     unsigned                          gzip_tested:1;  
  168.     unsigned                          gzip_ok:1;  
  169.     unsigned                          gzip_vary:1;  
  170. #endif  
  171.   
  172.     unsigned                          proxy:1;  
  173.     unsigned                          bypass_cache:1;  
  174.     unsigned                          no_cache:1;  
  175.   
  176.     /* 
  177.      * instead of using the request context data in 
  178.      * ngx_http_limit_conn_module and ngx_http_limit_req_module 
  179.      * we use the single bits in the request structure 
  180.      */  
  181.     unsigned                          limit_conn_set:1;  
  182.     unsigned                          limit_req_set:1;  
  183.   
  184. #if 0  
  185.     unsigned                          cacheable:1;  
  186. #endif  
  187.   
  188.     unsigned                          pipeline:1;  
  189.     unsigned                          chunked:1;  
  190.     unsigned                          header_only:1;  
  191.     //標誌位,爲1表示當前請求時keepalive請求  
  192.     unsigned                          keepalive:1;  
  193.     //延遲關閉標誌位  
  194.     unsigned                          lingering_close:1;  
  195.     //標誌位:爲1表示正在丟棄http請求中的包體  
  196.     unsigned                          discard_body:1;  
  197.     //標誌位:爲1表示請求的當前狀態是在作內部跳轉  
  198.     unsigned                          internal:1;  
  199.     unsigned                          error_page:1;  
  200.     unsigned                          ignore_content_encoding:1;  
  201.     unsigned                          filter_finalize:1;  
  202.     unsigned                          post_action:1;  
  203.     unsigned                          request_complete:1;  
  204.     unsigned                          request_output:1;  
  205.     //標誌位:爲1表示發生給客戶端的http響應頭已經發送  
  206.     unsigned                          header_sent:1;  
  207.     unsigned                          expect_tested:1;  
  208.     unsigned                          root_tested:1;  
  209.     unsigned                          done:1;  
  210.     unsigned                          logged:1;  
  211.   
  212.     //標誌位,表示緩衝中是否有待發送內容  
  213.     unsigned                          buffered:4;  
  214.   
  215.     unsigned                          main_filter_need_in_memory:1;  
  216.     unsigned                          filter_need_in_memory:1;  
  217.     unsigned                          filter_need_temporary:1;  
  218.     unsigned                          allow_ranges:1;  
  219.   
  220. #if (NGX_STAT_STUB)  
  221.     unsigned                          stat_reading:1;  
  222.     unsigned                          stat_writing:1;  
  223. #endif  
  224.   
  225.     /* used to parse HTTP headers */  
  226.   
  227.     //狀態機解析http時使用state來表示當前的解析狀態,須要檢查是否構成完成的http請求行  
  228.     ngx_uint_t                        state;  
  229.   
  230.     ngx_uint_t                        header_hash;  
  231.     ngx_uint_t                        lowcase_index;  
  232.     u_char                            lowcase_header[NGX_HTTP_LC_HEADER_LEN];  
  233.   
  234.     u_char                           *header_name_start;  
  235.     u_char                           *header_name_end;  
  236.     u_char                           *header_start;  
  237.     u_char                           *header_end;  
  238.   
  239.     /* 
  240.      * a memory that can be reused after parsing a request line 
  241.      * via ngx_http_ephemeral_t 
  242.      */  
  243.   
  244.     u_char                           *uri_start;  
  245.     u_char                           *uri_end;  
  246.     u_char                           *uri_ext;  
  247.     u_char                           *args_start;  
  248.     u_char                           *request_start;  
  249.     u_char                           *request_end;  
  250.     u_char                           *method_end;  
  251.     u_char                           *schema_start;  
  252.     u_char                           *schema_end;  
  253.     u_char                           *host_start;  
  254.     u_char                           *host_end;  
  255.     u_char                           *port_start;  
  256.     u_char                           *port_end;  
  257.   
  258.     unsigned                          http_minor:16;  
  259.     unsigned                          http_major:16;  
  260. };  
相關文章
相關標籤/搜索