Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_HTTP_REQUEST_H_INCLUDED_
0009 #define _NGX_HTTP_REQUEST_H_INCLUDED_
0010 
0011 
0012 #define NGX_HTTP_MAX_URI_CHANGES           10
0013 #define NGX_HTTP_MAX_SUBREQUESTS           50
0014 
0015 /* must be 2^n */
0016 #define NGX_HTTP_LC_HEADER_LEN             32
0017 
0018 
0019 #define NGX_HTTP_DISCARD_BUFFER_SIZE       4096
0020 #define NGX_HTTP_LINGERING_BUFFER_SIZE     4096
0021 
0022 
0023 #define NGX_HTTP_VERSION_9                 9
0024 #define NGX_HTTP_VERSION_10                1000
0025 #define NGX_HTTP_VERSION_11                1001
0026 #define NGX_HTTP_VERSION_20                2000
0027 
0028 #define NGX_HTTP_UNKNOWN                   0x0001
0029 #define NGX_HTTP_GET                       0x0002
0030 #define NGX_HTTP_HEAD                      0x0004
0031 #define NGX_HTTP_POST                      0x0008
0032 #define NGX_HTTP_PUT                       0x0010
0033 #define NGX_HTTP_DELETE                    0x0020
0034 #define NGX_HTTP_MKCOL                     0x0040
0035 #define NGX_HTTP_COPY                      0x0080
0036 #define NGX_HTTP_MOVE                      0x0100
0037 #define NGX_HTTP_OPTIONS                   0x0200
0038 #define NGX_HTTP_PROPFIND                  0x0400
0039 #define NGX_HTTP_PROPPATCH                 0x0800
0040 #define NGX_HTTP_LOCK                      0x1000
0041 #define NGX_HTTP_UNLOCK                    0x2000
0042 #define NGX_HTTP_PATCH                     0x4000
0043 #define NGX_HTTP_TRACE                     0x8000
0044 
0045 #define NGX_HTTP_CONNECTION_CLOSE          1
0046 #define NGX_HTTP_CONNECTION_KEEP_ALIVE     2
0047 
0048 
0049 #define NGX_NONE                           1
0050 
0051 
0052 #define NGX_HTTP_PARSE_HEADER_DONE         1
0053 
0054 #define NGX_HTTP_CLIENT_ERROR              10
0055 #define NGX_HTTP_PARSE_INVALID_METHOD      10
0056 #define NGX_HTTP_PARSE_INVALID_REQUEST     11
0057 #define NGX_HTTP_PARSE_INVALID_09_METHOD   12
0058 
0059 #define NGX_HTTP_PARSE_INVALID_HEADER      13
0060 
0061 
0062 /* unused                                  1 */
0063 #define NGX_HTTP_SUBREQUEST_IN_MEMORY      2
0064 #define NGX_HTTP_SUBREQUEST_WAITED         4
0065 #define NGX_HTTP_SUBREQUEST_CLONE          8
0066 
0067 #define NGX_HTTP_LOG_UNSAFE                1
0068 
0069 
0070 #define NGX_HTTP_CONTINUE                  100
0071 #define NGX_HTTP_SWITCHING_PROTOCOLS       101
0072 #define NGX_HTTP_PROCESSING                102
0073 
0074 #define NGX_HTTP_OK                        200
0075 #define NGX_HTTP_CREATED                   201
0076 #define NGX_HTTP_ACCEPTED                  202
0077 #define NGX_HTTP_NO_CONTENT                204
0078 #define NGX_HTTP_PARTIAL_CONTENT           206
0079 
0080 #define NGX_HTTP_SPECIAL_RESPONSE          300
0081 #define NGX_HTTP_MOVED_PERMANENTLY         301
0082 #define NGX_HTTP_MOVED_TEMPORARILY         302
0083 #define NGX_HTTP_SEE_OTHER                 303
0084 #define NGX_HTTP_NOT_MODIFIED              304
0085 #define NGX_HTTP_TEMPORARY_REDIRECT        307
0086 
0087 #define NGX_HTTP_BAD_REQUEST               400
0088 #define NGX_HTTP_UNAUTHORIZED              401
0089 #define NGX_HTTP_FORBIDDEN                 403
0090 #define NGX_HTTP_NOT_FOUND                 404
0091 #define NGX_HTTP_NOT_ALLOWED               405
0092 #define NGX_HTTP_REQUEST_TIME_OUT          408
0093 #define NGX_HTTP_CONFLICT                  409
0094 #define NGX_HTTP_LENGTH_REQUIRED           411
0095 #define NGX_HTTP_PRECONDITION_FAILED       412
0096 #define NGX_HTTP_REQUEST_ENTITY_TOO_LARGE  413
0097 #define NGX_HTTP_REQUEST_URI_TOO_LARGE     414
0098 #define NGX_HTTP_UNSUPPORTED_MEDIA_TYPE    415
0099 #define NGX_HTTP_RANGE_NOT_SATISFIABLE     416
0100 #define NGX_HTTP_MISDIRECTED_REQUEST       421
0101 #define NGX_HTTP_TOO_MANY_REQUESTS         429
0102 
0103 
0104 /* Our own HTTP codes */
0105 
0106 /* The special code to close connection without any response */
0107 #define NGX_HTTP_CLOSE                     444
0108 
0109 #define NGX_HTTP_NGINX_CODES               494
0110 
0111 #define NGX_HTTP_REQUEST_HEADER_TOO_LARGE  494
0112 
0113 #define NGX_HTTPS_CERT_ERROR               495
0114 #define NGX_HTTPS_NO_CERT                  496
0115 
0116 /*
0117  * We use the special code for the plain HTTP requests that are sent to
0118  * HTTPS port to distinguish it from 4XX in an error page redirection
0119  */
0120 #define NGX_HTTP_TO_HTTPS                  497
0121 
0122 /* 498 is the canceled code for the requests with invalid host name */
0123 
0124 /*
0125  * HTTP does not define the code for the case when a client closed
0126  * the connection while we are processing its request so we introduce
0127  * own code to log such situation when a client has closed the connection
0128  * before we even try to send the HTTP header to it
0129  */
0130 #define NGX_HTTP_CLIENT_CLOSED_REQUEST     499
0131 
0132 
0133 #define NGX_HTTP_INTERNAL_SERVER_ERROR     500
0134 #define NGX_HTTP_NOT_IMPLEMENTED           501
0135 #define NGX_HTTP_BAD_GATEWAY               502
0136 #define NGX_HTTP_SERVICE_UNAVAILABLE       503
0137 #define NGX_HTTP_GATEWAY_TIME_OUT          504
0138 #define NGX_HTTP_INSUFFICIENT_STORAGE      507
0139 
0140 
0141 #define NGX_HTTP_LOWLEVEL_BUFFERED         0xf0
0142 #define NGX_HTTP_WRITE_BUFFERED            0x10
0143 #define NGX_HTTP_GZIP_BUFFERED             0x20
0144 #define NGX_HTTP_SSI_BUFFERED              0x01
0145 #define NGX_HTTP_SUB_BUFFERED              0x02
0146 #define NGX_HTTP_COPY_BUFFERED             0x04
0147 
0148 
0149 typedef enum {
0150     NGX_HTTP_INITING_REQUEST_STATE = 0,
0151     NGX_HTTP_READING_REQUEST_STATE,
0152     NGX_HTTP_PROCESS_REQUEST_STATE,
0153 
0154     NGX_HTTP_CONNECT_UPSTREAM_STATE,
0155     NGX_HTTP_WRITING_UPSTREAM_STATE,
0156     NGX_HTTP_READING_UPSTREAM_STATE,
0157 
0158     NGX_HTTP_WRITING_REQUEST_STATE,
0159     NGX_HTTP_LINGERING_CLOSE_STATE,
0160     NGX_HTTP_KEEPALIVE_STATE
0161 } ngx_http_state_e;
0162 
0163 
0164 typedef struct {
0165     ngx_str_t                         name;
0166     ngx_uint_t                        offset;
0167     ngx_http_header_handler_pt        handler;
0168 } ngx_http_header_t;
0169 
0170 
0171 typedef struct {
0172     ngx_str_t                         name;
0173     ngx_uint_t                        offset;
0174 } ngx_http_header_out_t;
0175 
0176 
0177 typedef struct {
0178     ngx_list_t                        headers;
0179 
0180     ngx_table_elt_t                  *host;
0181     ngx_table_elt_t                  *connection;
0182     ngx_table_elt_t                  *if_modified_since;
0183     ngx_table_elt_t                  *if_unmodified_since;
0184     ngx_table_elt_t                  *if_match;
0185     ngx_table_elt_t                  *if_none_match;
0186     ngx_table_elt_t                  *user_agent;
0187     ngx_table_elt_t                  *referer;
0188     ngx_table_elt_t                  *content_length;
0189     ngx_table_elt_t                  *content_range;
0190     ngx_table_elt_t                  *content_type;
0191 
0192     ngx_table_elt_t                  *range;
0193     ngx_table_elt_t                  *if_range;
0194 
0195     ngx_table_elt_t                  *transfer_encoding;
0196     ngx_table_elt_t                  *expect;
0197     ngx_table_elt_t                  *upgrade;
0198 
0199 #if (NGX_HTTP_GZIP)
0200     ngx_table_elt_t                  *accept_encoding;
0201     ngx_table_elt_t                  *via;
0202 #endif
0203 
0204     ngx_table_elt_t                  *authorization;
0205 
0206     ngx_table_elt_t                  *keep_alive;
0207 
0208 #if (NGX_HTTP_X_FORWARDED_FOR)
0209     ngx_array_t                       x_forwarded_for;
0210 #endif
0211 
0212 #if (NGX_HTTP_REALIP)
0213     ngx_table_elt_t                  *x_real_ip;
0214 #endif
0215 
0216 #if (NGX_HTTP_HEADERS)
0217     ngx_table_elt_t                  *accept;
0218     ngx_table_elt_t                  *accept_language;
0219 #endif
0220 
0221 #if (NGX_HTTP_DAV)
0222     ngx_table_elt_t                  *depth;
0223     ngx_table_elt_t                  *destination;
0224     ngx_table_elt_t                  *overwrite;
0225     ngx_table_elt_t                  *date;
0226 #endif
0227 
0228     ngx_str_t                         user;
0229     ngx_str_t                         passwd;
0230 
0231     ngx_array_t                       cookies;
0232 
0233     ngx_str_t                         server;
0234     off_t                             content_length_n;
0235     time_t                            keep_alive_n;
0236 
0237     unsigned                          connection_type:2;
0238     unsigned                          chunked:1;
0239     unsigned                          msie:1;
0240     unsigned                          msie6:1;
0241     unsigned                          opera:1;
0242     unsigned                          gecko:1;
0243     unsigned                          chrome:1;
0244     unsigned                          safari:1;
0245     unsigned                          konqueror:1;
0246 } ngx_http_headers_in_t;
0247 
0248 
0249 typedef struct {
0250     ngx_list_t                        headers;
0251 
0252     ngx_uint_t                        status;
0253     ngx_str_t                         status_line;
0254 
0255     ngx_table_elt_t                  *server;
0256     ngx_table_elt_t                  *date;
0257     ngx_table_elt_t                  *content_length;
0258     ngx_table_elt_t                  *content_encoding;
0259     ngx_table_elt_t                  *location;
0260     ngx_table_elt_t                  *refresh;
0261     ngx_table_elt_t                  *last_modified;
0262     ngx_table_elt_t                  *content_range;
0263     ngx_table_elt_t                  *accept_ranges;
0264     ngx_table_elt_t                  *www_authenticate;
0265     ngx_table_elt_t                  *expires;
0266     ngx_table_elt_t                  *etag;
0267 
0268     ngx_str_t                        *override_charset;
0269 
0270     size_t                            content_type_len;
0271     ngx_str_t                         content_type;
0272     ngx_str_t                         charset;
0273     u_char                           *content_type_lowcase;
0274     ngx_uint_t                        content_type_hash;
0275 
0276     ngx_array_t                       cache_control;
0277 
0278     off_t                             content_length_n;
0279     off_t                             content_offset;
0280     time_t                            date_time;
0281     time_t                            last_modified_time;
0282 } ngx_http_headers_out_t;
0283 
0284 
0285 typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);
0286 
0287 typedef struct {
0288     ngx_temp_file_t                  *temp_file;
0289     ngx_chain_t                      *bufs;
0290     ngx_buf_t                        *buf;
0291     off_t                             rest;
0292     off_t                             received;
0293     ngx_chain_t                      *free;
0294     ngx_chain_t                      *busy;
0295     ngx_http_chunked_t               *chunked;
0296     ngx_http_client_body_handler_pt   post_handler;
0297 } ngx_http_request_body_t;
0298 
0299 
0300 typedef struct ngx_http_addr_conf_s  ngx_http_addr_conf_t;
0301 
0302 typedef struct {
0303     ngx_http_addr_conf_t             *addr_conf;
0304     ngx_http_conf_ctx_t              *conf_ctx;
0305 
0306 #if (NGX_HTTP_SSL || NGX_COMPAT)
0307     ngx_str_t                        *ssl_servername;
0308 #if (NGX_PCRE)
0309     ngx_http_regex_t                 *ssl_servername_regex;
0310 #endif
0311 #endif
0312 
0313     ngx_chain_t                      *busy;
0314     ngx_int_t                         nbusy;
0315 
0316     ngx_chain_t                      *free;
0317 
0318     unsigned                          ssl:1;
0319     unsigned                          proxy_protocol:1;
0320 } ngx_http_connection_t;
0321 
0322 
0323 typedef void (*ngx_http_cleanup_pt)(void *data);
0324 
0325 typedef struct ngx_http_cleanup_s  ngx_http_cleanup_t;
0326 
0327 struct ngx_http_cleanup_s {
0328     ngx_http_cleanup_pt               handler;
0329     void                             *data;
0330     ngx_http_cleanup_t               *next;
0331 };
0332 
0333 
0334 typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
0335     void *data, ngx_int_t rc);
0336 
0337 typedef struct {
0338     ngx_http_post_subrequest_pt       handler;
0339     void                             *data;
0340 } ngx_http_post_subrequest_t;
0341 
0342 
0343 typedef struct ngx_http_postponed_request_s  ngx_http_postponed_request_t;
0344 
0345 struct ngx_http_postponed_request_s {
0346     ngx_http_request_t               *request;
0347     ngx_chain_t                      *out;
0348     ngx_http_postponed_request_t     *next;
0349 };
0350 
0351 
0352 typedef struct ngx_http_posted_request_s  ngx_http_posted_request_t;
0353 
0354 struct ngx_http_posted_request_s {
0355     ngx_http_request_t               *request;
0356     ngx_http_posted_request_t        *next;
0357 };
0358 
0359 
0360 typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
0361 typedef void (*ngx_http_event_handler_pt)(ngx_http_request_t *r);
0362 
0363 
0364 struct ngx_http_request_s {
0365     uint32_t                          signature;         /* "HTTP" */
0366 
0367     ngx_connection_t                 *connection;
0368 
0369     void                            **ctx;
0370     void                            **main_conf;
0371     void                            **srv_conf;
0372     void                            **loc_conf;
0373 
0374     ngx_http_event_handler_pt         read_event_handler;
0375     ngx_http_event_handler_pt         write_event_handler;
0376 
0377 #if (NGX_HTTP_CACHE)
0378     ngx_http_cache_t                 *cache;
0379 #endif
0380 
0381     ngx_http_upstream_t              *upstream;
0382     ngx_array_t                      *upstream_states;
0383                                          /* of ngx_http_upstream_state_t */
0384 
0385     ngx_pool_t                       *pool;
0386     ngx_buf_t                        *header_in;
0387 
0388     ngx_http_headers_in_t             headers_in;
0389     ngx_http_headers_out_t            headers_out;
0390 
0391     ngx_http_request_body_t          *request_body;
0392 
0393     time_t                            lingering_time;
0394     time_t                            start_sec;
0395     ngx_msec_t                        start_msec;
0396 
0397     ngx_uint_t                        method;
0398     ngx_uint_t                        http_version;
0399 
0400     ngx_str_t                         request_line;
0401     ngx_str_t                         uri;
0402     ngx_str_t                         args;
0403     ngx_str_t                         exten;
0404     ngx_str_t                         unparsed_uri;
0405 
0406     ngx_str_t                         method_name;
0407     ngx_str_t                         http_protocol;
0408 
0409     ngx_chain_t                      *out;
0410     ngx_http_request_t               *main;
0411     ngx_http_request_t               *parent;
0412     ngx_http_postponed_request_t     *postponed;
0413     ngx_http_post_subrequest_t       *post_subrequest;
0414     ngx_http_posted_request_t        *posted_requests;
0415 
0416     ngx_int_t                         phase_handler;
0417     ngx_http_handler_pt               content_handler;
0418     ngx_uint_t                        access_code;
0419 
0420     ngx_http_variable_value_t        *variables;
0421 
0422 #if (NGX_PCRE)
0423     ngx_uint_t                        ncaptures;
0424     int                              *captures;
0425     u_char                           *captures_data;
0426 #endif
0427 
0428     size_t                            limit_rate;
0429     size_t                            limit_rate_after;
0430 
0431     /* used to learn the Apache compatible response length without a header */
0432     size_t                            header_size;
0433 
0434     off_t                             request_length;
0435 
0436     ngx_uint_t                        err_status;
0437 
0438     ngx_http_connection_t            *http_connection;
0439     ngx_http_v2_stream_t             *stream;
0440 
0441     ngx_http_log_handler_pt           log_handler;
0442 
0443     ngx_http_cleanup_t               *cleanup;
0444 
0445     unsigned                          count:16;
0446     unsigned                          subrequests:8;
0447     unsigned                          blocked:8;
0448 
0449     unsigned                          aio:1;
0450 
0451     unsigned                          http_state:4;
0452 
0453     /* URI with "/." and on Win32 with "//" */
0454     unsigned                          complex_uri:1;
0455 
0456     /* URI with "%" */
0457     unsigned                          quoted_uri:1;
0458 
0459     /* URI with "+" */
0460     unsigned                          plus_in_uri:1;
0461 
0462     /* URI with " " */
0463     unsigned                          space_in_uri:1;
0464 
0465     unsigned                          invalid_header:1;
0466 
0467     unsigned                          add_uri_to_alias:1;
0468     unsigned                          valid_location:1;
0469     unsigned                          valid_unparsed_uri:1;
0470     unsigned                          uri_changed:1;
0471     unsigned                          uri_changes:4;
0472 
0473     unsigned                          request_body_in_single_buf:1;
0474     unsigned                          request_body_in_file_only:1;
0475     unsigned                          request_body_in_persistent_file:1;
0476     unsigned                          request_body_in_clean_file:1;
0477     unsigned                          request_body_file_group_access:1;
0478     unsigned                          request_body_file_log_level:3;
0479     unsigned                          request_body_no_buffering:1;
0480 
0481     unsigned                          subrequest_in_memory:1;
0482     unsigned                          waited:1;
0483 
0484 #if (NGX_HTTP_CACHE)
0485     unsigned                          cached:1;
0486     unsigned                          cache_updater:1;
0487 #endif
0488 
0489 #if (NGX_HTTP_GZIP)
0490     unsigned                          gzip_tested:1;
0491     unsigned                          gzip_ok:1;
0492     unsigned                          gzip_vary:1;
0493 #endif
0494 
0495     unsigned                          proxy:1;
0496     unsigned                          bypass_cache:1;
0497     unsigned                          no_cache:1;
0498 
0499     /*
0500      * instead of using the request context data in
0501      * ngx_http_limit_conn_module and ngx_http_limit_req_module
0502      * we use the single bits in the request structure
0503      */
0504     unsigned                          limit_conn_set:1;
0505     unsigned                          limit_req_set:1;
0506 
0507 #if 0
0508     unsigned                          cacheable:1;
0509 #endif
0510 
0511     unsigned                          pipeline:1;
0512     unsigned                          chunked:1;
0513     unsigned                          header_only:1;
0514     unsigned                          keepalive:1;
0515     unsigned                          lingering_close:1;
0516     unsigned                          discard_body:1;
0517     unsigned                          reading_body:1;
0518     unsigned                          internal:1;
0519     unsigned                          error_page:1;
0520     unsigned                          filter_finalize:1;
0521     unsigned                          post_action:1;
0522     unsigned                          request_complete:1;
0523     unsigned                          request_output:1;
0524     unsigned                          header_sent:1;
0525     unsigned                          expect_tested:1;
0526     unsigned                          root_tested:1;
0527     unsigned                          done:1;
0528     unsigned                          logged:1;
0529 
0530     unsigned                          buffered:4;
0531 
0532     unsigned                          main_filter_need_in_memory:1;
0533     unsigned                          filter_need_in_memory:1;
0534     unsigned                          filter_need_temporary:1;
0535     unsigned                          allow_ranges:1;
0536     unsigned                          subrequest_ranges:1;
0537     unsigned                          single_range:1;
0538     unsigned                          disable_not_modified:1;
0539     unsigned                          stat_reading:1;
0540     unsigned                          stat_writing:1;
0541     unsigned                          stat_processing:1;
0542 
0543     unsigned                          health_check:1;
0544 
0545     /* used to parse HTTP headers */
0546 
0547     ngx_uint_t                        state;
0548 
0549     ngx_uint_t                        header_hash;
0550     ngx_uint_t                        lowcase_index;
0551     u_char                            lowcase_header[NGX_HTTP_LC_HEADER_LEN];
0552 
0553     u_char                           *header_name_start;
0554     u_char                           *header_name_end;
0555     u_char                           *header_start;
0556     u_char                           *header_end;
0557 
0558     /*
0559      * a memory that can be reused after parsing a request line
0560      * via ngx_http_ephemeral_t
0561      */
0562 
0563     u_char                           *uri_start;
0564     u_char                           *uri_end;
0565     u_char                           *uri_ext;
0566     u_char                           *args_start;
0567     u_char                           *request_start;
0568     u_char                           *request_end;
0569     u_char                           *method_end;
0570     u_char                           *schema_start;
0571     u_char                           *schema_end;
0572     u_char                           *host_start;
0573     u_char                           *host_end;
0574     u_char                           *port_start;
0575     u_char                           *port_end;
0576 
0577     unsigned                          http_minor:16;
0578     unsigned                          http_major:16;
0579 };
0580 
0581 
0582 typedef struct {
0583     ngx_http_posted_request_t         terminal_posted_request;
0584 } ngx_http_ephemeral_t;
0585 
0586 
0587 #define ngx_http_ephemeral(r)  (void *) (&r->uri_start)
0588 
0589 
0590 extern ngx_http_header_t       ngx_http_headers_in[];
0591 extern ngx_http_header_out_t   ngx_http_headers_out[];
0592 
0593 
0594 #define ngx_http_set_log_request(log, r)                                      \
0595     ((ngx_http_log_ctx_t *) log->data)->current_request = r
0596 
0597 
0598 #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */