Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.2 ]​[ nginx-1.12.0 ]​

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