src/http/ngx_http_request.h - nginx-1.7.10

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_HTTP_REQUEST_H_INCLUDED_
  6. #define _NGX_HTTP_REQUEST_H_INCLUDED_


  7. #define NGX_HTTP_MAX_URI_CHANGES           10
  8. #define NGX_HTTP_MAX_SUBREQUESTS           200

  9. /* must be 2^n */
  10. #define NGX_HTTP_LC_HEADER_LEN             32


  11. #define NGX_HTTP_DISCARD_BUFFER_SIZE       4096
  12. #define NGX_HTTP_LINGERING_BUFFER_SIZE     4096


  13. #define NGX_HTTP_VERSION_9                 9
  14. #define NGX_HTTP_VERSION_10                1000
  15. #define NGX_HTTP_VERSION_11                1001

  16. #define NGX_HTTP_UNKNOWN                   0x0001
  17. #define NGX_HTTP_GET                       0x0002
  18. #define NGX_HTTP_HEAD                      0x0004
  19. #define NGX_HTTP_POST                      0x0008
  20. #define NGX_HTTP_PUT                       0x0010
  21. #define NGX_HTTP_DELETE                    0x0020
  22. #define NGX_HTTP_MKCOL                     0x0040
  23. #define NGX_HTTP_COPY                      0x0080
  24. #define NGX_HTTP_MOVE                      0x0100
  25. #define NGX_HTTP_OPTIONS                   0x0200
  26. #define NGX_HTTP_PROPFIND                  0x0400
  27. #define NGX_HTTP_PROPPATCH                 0x0800
  28. #define NGX_HTTP_LOCK                      0x1000
  29. #define NGX_HTTP_UNLOCK                    0x2000
  30. #define NGX_HTTP_PATCH                     0x4000
  31. #define NGX_HTTP_TRACE                     0x8000

  32. #define NGX_HTTP_CONNECTION_CLOSE          1
  33. #define NGX_HTTP_CONNECTION_KEEP_ALIVE     2


  34. #define NGX_NONE                           1


  35. #define NGX_HTTP_PARSE_HEADER_DONE         1

  36. #define NGX_HTTP_CLIENT_ERROR              10
  37. #define NGX_HTTP_PARSE_INVALID_METHOD      10
  38. #define NGX_HTTP_PARSE_INVALID_REQUEST     11
  39. #define NGX_HTTP_PARSE_INVALID_09_METHOD   12

  40. #define NGX_HTTP_PARSE_INVALID_HEADER      13


  41. /* unused                                  1 */
  42. #define NGX_HTTP_SUBREQUEST_IN_MEMORY      2
  43. #define NGX_HTTP_SUBREQUEST_WAITED         4
  44. #define NGX_HTTP_LOG_UNSAFE                8


  45. #define NGX_HTTP_CONTINUE                  100
  46. #define NGX_HTTP_SWITCHING_PROTOCOLS       101
  47. #define NGX_HTTP_PROCESSING                102

  48. #define NGX_HTTP_OK                        200
  49. #define NGX_HTTP_CREATED                   201
  50. #define NGX_HTTP_ACCEPTED                  202
  51. #define NGX_HTTP_NO_CONTENT                204
  52. #define NGX_HTTP_PARTIAL_CONTENT           206

  53. #define NGX_HTTP_SPECIAL_RESPONSE          300
  54. #define NGX_HTTP_MOVED_PERMANENTLY         301
  55. #define NGX_HTTP_MOVED_TEMPORARILY         302
  56. #define NGX_HTTP_SEE_OTHER                 303
  57. #define NGX_HTTP_NOT_MODIFIED              304
  58. #define NGX_HTTP_TEMPORARY_REDIRECT        307

  59. #define NGX_HTTP_BAD_REQUEST               400
  60. #define NGX_HTTP_UNAUTHORIZED              401
  61. #define NGX_HTTP_FORBIDDEN                 403
  62. #define NGX_HTTP_NOT_FOUND                 404
  63. #define NGX_HTTP_NOT_ALLOWED               405
  64. #define NGX_HTTP_REQUEST_TIME_OUT          408
  65. #define NGX_HTTP_CONFLICT                  409
  66. #define NGX_HTTP_LENGTH_REQUIRED           411
  67. #define NGX_HTTP_PRECONDITION_FAILED       412
  68. #define NGX_HTTP_REQUEST_ENTITY_TOO_LARGE  413
  69. #define NGX_HTTP_REQUEST_URI_TOO_LARGE     414
  70. #define NGX_HTTP_UNSUPPORTED_MEDIA_TYPE    415
  71. #define NGX_HTTP_RANGE_NOT_SATISFIABLE     416


  72. /* Our own HTTP codes */

  73. /* The special code to close connection without any response */
  74. #define NGX_HTTP_CLOSE                     444

  75. #define NGX_HTTP_NGINX_CODES               494

  76. #define NGX_HTTP_REQUEST_HEADER_TOO_LARGE  494

  77. #define NGX_HTTPS_CERT_ERROR               495
  78. #define NGX_HTTPS_NO_CERT                  496

  79. /*
  80. * We use the special code for the plain HTTP requests that are sent to
  81. * HTTPS port to distinguish it from 4XX in an error page redirection
  82. */
  83. #define NGX_HTTP_TO_HTTPS                  497

  84. /* 498 is the canceled code for the requests with invalid host name */

  85. /*
  86. * HTTP does not define the code for the case when a client closed
  87. * the connection while we are processing its request so we introduce
  88. * own code to log such situation when a client has closed the connection
  89. * before we even try to send the HTTP header to it
  90. */
  91. #define NGX_HTTP_CLIENT_CLOSED_REQUEST     499


  92. #define NGX_HTTP_INTERNAL_SERVER_ERROR     500
  93. #define NGX_HTTP_NOT_IMPLEMENTED           501
  94. #define NGX_HTTP_BAD_GATEWAY               502
  95. #define NGX_HTTP_SERVICE_UNAVAILABLE       503
  96. #define NGX_HTTP_GATEWAY_TIME_OUT          504
  97. #define NGX_HTTP_INSUFFICIENT_STORAGE      507


  98. #define NGX_HTTP_LOWLEVEL_BUFFERED         0xf0
  99. #define NGX_HTTP_WRITE_BUFFERED            0x10
  100. #define NGX_HTTP_GZIP_BUFFERED             0x20
  101. #define NGX_HTTP_SSI_BUFFERED              0x01
  102. #define NGX_HTTP_SUB_BUFFERED              0x02
  103. #define NGX_HTTP_COPY_BUFFERED             0x04


  104. typedef enum {
  105.     NGX_HTTP_INITING_REQUEST_STATE = 0,
  106.     NGX_HTTP_READING_REQUEST_STATE,
  107.     NGX_HTTP_PROCESS_REQUEST_STATE,

  108.     NGX_HTTP_CONNECT_UPSTREAM_STATE,
  109.     NGX_HTTP_WRITING_UPSTREAM_STATE,
  110.     NGX_HTTP_READING_UPSTREAM_STATE,

  111.     NGX_HTTP_WRITING_REQUEST_STATE,
  112.     NGX_HTTP_LINGERING_CLOSE_STATE,
  113.     NGX_HTTP_KEEPALIVE_STATE
  114. } ngx_http_state_e;


  115. typedef struct {
  116.     ngx_str_t                         name;
  117.     ngx_uint_t                        offset;
  118.     ngx_http_header_handler_pt        handler;
  119. } ngx_http_header_t;


  120. typedef struct {
  121.     ngx_str_t                         name;
  122.     ngx_uint_t                        offset;
  123. } ngx_http_header_out_t;


  124. typedef struct {
  125.     ngx_list_t                        headers;

  126.     ngx_table_elt_t                  *host;
  127.     ngx_table_elt_t                  *connection;
  128.     ngx_table_elt_t                  *if_modified_since;
  129.     ngx_table_elt_t                  *if_unmodified_since;
  130.     ngx_table_elt_t                  *if_match;
  131.     ngx_table_elt_t                  *if_none_match;
  132.     ngx_table_elt_t                  *user_agent;
  133.     ngx_table_elt_t                  *referer;
  134.     ngx_table_elt_t                  *content_length;
  135.     ngx_table_elt_t                  *content_type;

  136.     ngx_table_elt_t                  *range;
  137.     ngx_table_elt_t                  *if_range;

  138.     ngx_table_elt_t                  *transfer_encoding;
  139.     ngx_table_elt_t                  *expect;
  140.     ngx_table_elt_t                  *upgrade;

  141. #if (NGX_HTTP_GZIP)
  142.     ngx_table_elt_t                  *accept_encoding;
  143.     ngx_table_elt_t                  *via;
  144. #endif

  145.     ngx_table_elt_t                  *authorization;

  146.     ngx_table_elt_t                  *keep_alive;

  147. #if (NGX_HTTP_X_FORWARDED_FOR)
  148.     ngx_array_t                       x_forwarded_for;
  149. #endif

  150. #if (NGX_HTTP_REALIP)
  151.     ngx_table_elt_t                  *x_real_ip;
  152. #endif

  153. #if (NGX_HTTP_HEADERS)
  154.     ngx_table_elt_t                  *accept;
  155.     ngx_table_elt_t                  *accept_language;
  156. #endif

  157. #if (NGX_HTTP_DAV)
  158.     ngx_table_elt_t                  *depth;
  159.     ngx_table_elt_t                  *destination;
  160.     ngx_table_elt_t                  *overwrite;
  161.     ngx_table_elt_t                  *date;
  162. #endif

  163.     ngx_str_t                         user;
  164.     ngx_str_t                         passwd;

  165.     ngx_array_t                       cookies;

  166.     ngx_str_t                         server;
  167.     off_t                             content_length_n;
  168.     time_t                            keep_alive_n;

  169.     unsigned                          connection_type:2;
  170.     unsigned                          chunked:1;
  171.     unsigned                          msie:1;
  172.     unsigned                          msie6:1;
  173.     unsigned                          opera:1;
  174.     unsigned                          gecko:1;
  175.     unsigned                          chrome:1;
  176.     unsigned                          safari:1;
  177.     unsigned                          konqueror:1;
  178. } ngx_http_headers_in_t;


  179. typedef struct {
  180.     ngx_list_t                        headers;

  181.     ngx_uint_t                        status;
  182.     ngx_str_t                         status_line;

  183.     ngx_table_elt_t                  *server;
  184.     ngx_table_elt_t                  *date;
  185.     ngx_table_elt_t                  *content_length;
  186.     ngx_table_elt_t                  *content_encoding;
  187.     ngx_table_elt_t                  *location;
  188.     ngx_table_elt_t                  *refresh;
  189.     ngx_table_elt_t                  *last_modified;
  190.     ngx_table_elt_t                  *content_range;
  191.     ngx_table_elt_t                  *accept_ranges;
  192.     ngx_table_elt_t                  *www_authenticate;
  193.     ngx_table_elt_t                  *expires;
  194.     ngx_table_elt_t                  *etag;

  195.     ngx_str_t                        *override_charset;

  196.     size_t                            content_type_len;
  197.     ngx_str_t                         content_type;
  198.     ngx_str_t                         charset;
  199.     u_char                           *content_type_lowcase;
  200.     ngx_uint_t                        content_type_hash;

  201.     ngx_array_t                       cache_control;

  202.     off_t                             content_length_n;
  203.     time_t                            date_time;
  204.     time_t                            last_modified_time;
  205. } ngx_http_headers_out_t;


  206. typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);

  207. typedef struct {
  208.     ngx_temp_file_t                  *temp_file;
  209.     ngx_chain_t                      *bufs;
  210.     ngx_buf_t                        *buf;
  211.     off_t                             rest;
  212.     ngx_chain_t                      *free;
  213.     ngx_chain_t                      *busy;
  214.     ngx_http_chunked_t               *chunked;
  215.     ngx_http_client_body_handler_pt   post_handler;
  216. } ngx_http_request_body_t;


  217. typedef struct ngx_http_addr_conf_s  ngx_http_addr_conf_t;

  218. typedef struct {
  219.     ngx_http_addr_conf_t             *addr_conf;
  220.     ngx_http_conf_ctx_t              *conf_ctx;

  221. #if (NGX_HTTP_SSL && defined SSL_CTRL_SET_TLSEXT_HOSTNAME)
  222.     ngx_str_t                        *ssl_servername;
  223. #if (NGX_PCRE)
  224.     ngx_http_regex_t                 *ssl_servername_regex;
  225. #endif
  226. #endif

  227.     ngx_buf_t                       **busy;
  228.     ngx_int_t                         nbusy;

  229.     ngx_buf_t                       **free;
  230.     ngx_int_t                         nfree;

  231. #if (NGX_HTTP_SSL)
  232.     unsigned                          ssl:1;
  233. #endif
  234.     unsigned                          proxy_protocol:1;
  235. } ngx_http_connection_t;


  236. typedef void (*ngx_http_cleanup_pt)(void *data);

  237. typedef struct ngx_http_cleanup_s  ngx_http_cleanup_t;

  238. struct ngx_http_cleanup_s {
  239.     ngx_http_cleanup_pt               handler;
  240.     void                             *data;
  241.     ngx_http_cleanup_t               *next;
  242. };


  243. typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
  244.     void *data, ngx_int_t rc);

  245. typedef struct {
  246.     ngx_http_post_subrequest_pt       handler;
  247.     void                             *data;
  248. } ngx_http_post_subrequest_t;


  249. typedef struct ngx_http_postponed_request_s  ngx_http_postponed_request_t;

  250. struct ngx_http_postponed_request_s {
  251.     ngx_http_request_t               *request;
  252.     ngx_chain_t                      *out;
  253.     ngx_http_postponed_request_t     *next;
  254. };


  255. typedef struct ngx_http_posted_request_s  ngx_http_posted_request_t;

  256. struct ngx_http_posted_request_s {
  257.     ngx_http_request_t               *request;
  258.     ngx_http_posted_request_t        *next;
  259. };


  260. typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
  261. typedef void (*ngx_http_event_handler_pt)(ngx_http_request_t *r);


  262. struct ngx_http_request_s {
  263.     uint32_t                          signature;         /* "HTTP" */

  264.     ngx_connection_t                 *connection;

  265.     void                            **ctx;
  266.     void                            **main_conf;
  267.     void                            **srv_conf;
  268.     void                            **loc_conf;

  269.     ngx_http_event_handler_pt         read_event_handler;
  270.     ngx_http_event_handler_pt         write_event_handler;

  271. #if (NGX_HTTP_CACHE)
  272.     ngx_http_cache_t                 *cache;
  273. #endif

  274.     ngx_http_upstream_t              *upstream;
  275.     ngx_array_t                      *upstream_states;
  276.                                          /* of ngx_http_upstream_state_t */

  277.     ngx_pool_t                       *pool;
  278.     ngx_buf_t                        *header_in;

  279.     ngx_http_headers_in_t             headers_in;
  280.     ngx_http_headers_out_t            headers_out;

  281.     ngx_http_request_body_t          *request_body;

  282.     time_t                            lingering_time;
  283.     time_t                            start_sec;
  284.     ngx_msec_t                        start_msec;

  285.     ngx_uint_t                        method;
  286.     ngx_uint_t                        http_version;

  287.     ngx_str_t                         request_line;
  288.     ngx_str_t                         uri;
  289.     ngx_str_t                         args;
  290.     ngx_str_t                         exten;
  291.     ngx_str_t                         unparsed_uri;

  292.     ngx_str_t                         method_name;
  293.     ngx_str_t                         http_protocol;

  294.     ngx_chain_t                      *out;
  295.     ngx_http_request_t               *main;
  296.     ngx_http_request_t               *parent;
  297.     ngx_http_postponed_request_t     *postponed;
  298.     ngx_http_post_subrequest_t       *post_subrequest;
  299.     ngx_http_posted_request_t        *posted_requests;

  300.     ngx_int_t                         phase_handler;
  301.     ngx_http_handler_pt               content_handler;
  302.     ngx_uint_t                        access_code;

  303.     ngx_http_variable_value_t        *variables;

  304. #if (NGX_PCRE)
  305.     ngx_uint_t                        ncaptures;
  306.     int                              *captures;
  307.     u_char                           *captures_data;
  308. #endif

  309.     size_t                            limit_rate;
  310.     size_t                            limit_rate_after;

  311.     /* used to learn the Apache compatible response length without a header */
  312.     size_t                            header_size;

  313.     off_t                             request_length;

  314.     ngx_uint_t                        err_status;

  315.     ngx_http_connection_t            *http_connection;
  316. #if (NGX_HTTP_SPDY)
  317.     ngx_http_spdy_stream_t           *spdy_stream;
  318. #endif

  319.     ngx_http_log_handler_pt           log_handler;

  320.     ngx_http_cleanup_t               *cleanup;

  321.     unsigned                          subrequests:8;
  322.     unsigned                          count:8;
  323.     unsigned                          blocked:8;

  324.     unsigned                          aio:1;

  325.     unsigned                          http_state:4;

  326.     /* URI with "/." and on Win32 with "//" */
  327.     unsigned                          complex_uri:1;

  328.     /* URI with "%" */
  329.     unsigned                          quoted_uri:1;

  330.     /* URI with "+" */
  331.     unsigned                          plus_in_uri:1;

  332.     /* URI with " " */
  333.     unsigned                          space_in_uri:1;

  334.     unsigned                          invalid_header:1;

  335.     unsigned                          add_uri_to_alias:1;
  336.     unsigned                          valid_location:1;
  337.     unsigned                          valid_unparsed_uri:1;
  338.     unsigned                          uri_changed:1;
  339.     unsigned                          uri_changes:4;

  340.     unsigned                          request_body_in_single_buf:1;
  341.     unsigned                          request_body_in_file_only:1;
  342.     unsigned                          request_body_in_persistent_file:1;
  343.     unsigned                          request_body_in_clean_file:1;
  344.     unsigned                          request_body_file_group_access:1;
  345.     unsigned                          request_body_file_log_level:3;

  346.     unsigned                          subrequest_in_memory:1;
  347.     unsigned                          waited:1;

  348. #if (NGX_HTTP_CACHE)
  349.     unsigned                          cached:1;
  350. #endif

  351. #if (NGX_HTTP_GZIP)
  352.     unsigned                          gzip_tested:1;
  353.     unsigned                          gzip_ok:1;
  354.     unsigned                          gzip_vary:1;
  355. #endif

  356.     unsigned                          proxy:1;
  357.     unsigned                          bypass_cache:1;
  358.     unsigned                          no_cache:1;

  359.     /*
  360.      * instead of using the request context data in
  361.      * ngx_http_limit_conn_module and ngx_http_limit_req_module
  362.      * we use the single bits in the request structure
  363.      */
  364.     unsigned                          limit_conn_set:1;
  365.     unsigned                          limit_req_set:1;

  366. #if 0
  367.     unsigned                          cacheable:1;
  368. #endif

  369.     unsigned                          pipeline:1;
  370.     unsigned                          chunked:1;
  371.     unsigned                          header_only:1;
  372.     unsigned                          keepalive:1;
  373.     unsigned                          lingering_close:1;
  374.     unsigned                          discard_body:1;
  375.     unsigned                          internal:1;
  376.     unsigned                          error_page:1;
  377.     unsigned                          filter_finalize:1;
  378.     unsigned                          post_action:1;
  379.     unsigned                          request_complete:1;
  380.     unsigned                          request_output:1;
  381.     unsigned                          header_sent:1;
  382.     unsigned                          expect_tested:1;
  383.     unsigned                          root_tested:1;
  384.     unsigned                          done:1;
  385.     unsigned                          logged:1;

  386.     unsigned                          buffered:4;

  387.     unsigned                          main_filter_need_in_memory:1;
  388.     unsigned                          filter_need_in_memory:1;
  389.     unsigned                          filter_need_temporary:1;
  390.     unsigned                          allow_ranges:1;
  391.     unsigned                          single_range:1;
  392.     unsigned                          disable_not_modified:1;

  393. #if (NGX_STAT_STUB)
  394.     unsigned                          stat_reading:1;
  395.     unsigned                          stat_writing:1;
  396. #endif

  397.     /* used to parse HTTP headers */

  398.     ngx_uint_t                        state;

  399.     ngx_uint_t                        header_hash;
  400.     ngx_uint_t                        lowcase_index;
  401.     u_char                            lowcase_header[NGX_HTTP_LC_HEADER_LEN];

  402.     u_char                           *header_name_start;
  403.     u_char                           *header_name_end;
  404.     u_char                           *header_start;
  405.     u_char                           *header_end;

  406.     /*
  407.      * a memory that can be reused after parsing a request line
  408.      * via ngx_http_ephemeral_t
  409.      */

  410.     u_char                           *uri_start;
  411.     u_char                           *uri_end;
  412.     u_char                           *uri_ext;
  413.     u_char                           *args_start;
  414.     u_char                           *request_start;
  415.     u_char                           *request_end;
  416.     u_char                           *method_end;
  417.     u_char                           *schema_start;
  418.     u_char                           *schema_end;
  419.     u_char                           *host_start;
  420.     u_char                           *host_end;
  421.     u_char                           *port_start;
  422.     u_char                           *port_end;

  423.     unsigned                          http_minor:16;
  424.     unsigned                          http_major:16;
  425. };


  426. typedef struct {
  427.     ngx_http_posted_request_t         terminal_posted_request;
  428. #if (NGX_HAVE_AIO_SENDFILE)
  429.     u_char                            aio_preload;
  430. #endif
  431. } ngx_http_ephemeral_t;


  432. extern ngx_http_header_t       ngx_http_headers_in[];
  433. extern ngx_http_header_out_t   ngx_http_headers_out[];


  434. #define ngx_http_set_connection_log(c, l)                                     \
  435.                                                                               \
  436.     c->log->file = l->file;                                                   \
  437.     c->log->next = l->next;                                                   \
  438.     c->log->writer = l->writer;                                               \
  439.     c->log->wdata = l->wdata;                                                 \
  440.     if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {                    \
  441.         c->log->log_level = l->log_level;                                     \
  442.     }


  443. #define ngx_http_set_log_request(log, r)                                      \
  444.     ((ngx_http_log_ctx_t *) log->data)->current_request = r


  445. #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */