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_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                  *te;
0201     ngx_table_elt_t                  *expect;
0202     ngx_table_elt_t                  *upgrade;
0203 
0204 #if (NGX_HTTP_GZIP || NGX_HTTP_HEADERS)
0205     ngx_table_elt_t                  *accept_encoding;
0206     ngx_table_elt_t                  *via;
0207 #endif
0208 
0209     ngx_table_elt_t                  *authorization;
0210 
0211     ngx_table_elt_t                  *keep_alive;
0212 
0213 #if (NGX_HTTP_X_FORWARDED_FOR)
0214     ngx_array_t                       x_forwarded_for;
0215 #endif
0216 
0217 #if (NGX_HTTP_REALIP)
0218     ngx_table_elt_t                  *x_real_ip;
0219 #endif
0220 
0221 #if (NGX_HTTP_HEADERS)
0222     ngx_table_elt_t                  *accept;
0223     ngx_table_elt_t                  *accept_language;
0224 #endif
0225 
0226 #if (NGX_HTTP_DAV)
0227     ngx_table_elt_t                  *depth;
0228     ngx_table_elt_t                  *destination;
0229     ngx_table_elt_t                  *overwrite;
0230     ngx_table_elt_t                  *date;
0231 #endif
0232 
0233     ngx_str_t                         user;
0234     ngx_str_t                         passwd;
0235 
0236     ngx_array_t                       cookies;
0237 
0238     ngx_str_t                         server;
0239     off_t                             content_length_n;
0240     time_t                            keep_alive_n;
0241 
0242     unsigned                          connection_type:2;
0243     unsigned                          chunked:1;
0244     unsigned                          msie:1;
0245     unsigned                          msie6:1;
0246     unsigned                          opera:1;
0247     unsigned                          gecko:1;
0248     unsigned                          chrome:1;
0249     unsigned                          safari:1;
0250     unsigned                          konqueror:1;
0251 } ngx_http_headers_in_t;
0252 
0253 
0254 typedef struct {
0255     ngx_list_t                        headers;
0256     ngx_list_t                        trailers;
0257 
0258     ngx_uint_t                        status;
0259     ngx_str_t                         status_line;
0260 
0261     ngx_table_elt_t                  *server;
0262     ngx_table_elt_t                  *date;
0263     ngx_table_elt_t                  *content_length;
0264     ngx_table_elt_t                  *content_encoding;
0265     ngx_table_elt_t                  *location;
0266     ngx_table_elt_t                  *refresh;
0267     ngx_table_elt_t                  *last_modified;
0268     ngx_table_elt_t                  *content_range;
0269     ngx_table_elt_t                  *accept_ranges;
0270     ngx_table_elt_t                  *www_authenticate;
0271     ngx_table_elt_t                  *expires;
0272     ngx_table_elt_t                  *etag;
0273 
0274     ngx_str_t                        *override_charset;
0275 
0276     size_t                            content_type_len;
0277     ngx_str_t                         content_type;
0278     ngx_str_t                         charset;
0279     u_char                           *content_type_lowcase;
0280     ngx_uint_t                        content_type_hash;
0281 
0282     ngx_array_t                       cache_control;
0283     ngx_array_t                       link;
0284 
0285     off_t                             content_length_n;
0286     off_t                             content_offset;
0287     time_t                            date_time;
0288     time_t                            last_modified_time;
0289 } ngx_http_headers_out_t;
0290 
0291 
0292 typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);
0293 
0294 typedef struct {
0295     ngx_temp_file_t                  *temp_file;
0296     ngx_chain_t                      *bufs;
0297     ngx_buf_t                        *buf;
0298     off_t                             rest;
0299     off_t                             received;
0300     ngx_chain_t                      *free;
0301     ngx_chain_t                      *busy;
0302     ngx_http_chunked_t               *chunked;
0303     ngx_http_client_body_handler_pt   post_handler;
0304 } ngx_http_request_body_t;
0305 
0306 
0307 typedef struct ngx_http_addr_conf_s  ngx_http_addr_conf_t;
0308 
0309 typedef struct {
0310     ngx_http_addr_conf_t             *addr_conf;
0311     ngx_http_conf_ctx_t              *conf_ctx;
0312 
0313 #if (NGX_HTTP_SSL || NGX_COMPAT)
0314     ngx_str_t                        *ssl_servername;
0315 #if (NGX_PCRE)
0316     ngx_http_regex_t                 *ssl_servername_regex;
0317 #endif
0318 #endif
0319 
0320     ngx_chain_t                      *busy;
0321     ngx_int_t                         nbusy;
0322 
0323     ngx_chain_t                      *free;
0324 
0325     unsigned                          ssl:1;
0326     unsigned                          proxy_protocol:1;
0327 } ngx_http_connection_t;
0328 
0329 
0330 typedef void (*ngx_http_cleanup_pt)(void *data);
0331 
0332 typedef struct ngx_http_cleanup_s  ngx_http_cleanup_t;
0333 
0334 struct ngx_http_cleanup_s {
0335     ngx_http_cleanup_pt               handler;
0336     void                             *data;
0337     ngx_http_cleanup_t               *next;
0338 };
0339 
0340 
0341 typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
0342     void *data, ngx_int_t rc);
0343 
0344 typedef struct {
0345     ngx_http_post_subrequest_pt       handler;
0346     void                             *data;
0347 } ngx_http_post_subrequest_t;
0348 
0349 
0350 typedef struct ngx_http_postponed_request_s  ngx_http_postponed_request_t;
0351 
0352 struct ngx_http_postponed_request_s {
0353     ngx_http_request_t               *request;
0354     ngx_chain_t                      *out;
0355     ngx_http_postponed_request_t     *next;
0356 };
0357 
0358 
0359 typedef struct ngx_http_posted_request_s  ngx_http_posted_request_t;
0360 
0361 struct ngx_http_posted_request_s {
0362     ngx_http_request_t               *request;
0363     ngx_http_posted_request_t        *next;
0364 };
0365 
0366 
0367 typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
0368 typedef void (*ngx_http_event_handler_pt)(ngx_http_request_t *r);
0369 
0370 
0371 struct ngx_http_request_s {
0372     uint32_t                          signature;         /* "HTTP" */
0373 
0374     ngx_connection_t                 *connection;
0375 
0376     void                            **ctx;
0377     void                            **main_conf;
0378     void                            **srv_conf;
0379     void                            **loc_conf;
0380 
0381     ngx_http_event_handler_pt         read_event_handler;
0382     ngx_http_event_handler_pt         write_event_handler;
0383 
0384 #if (NGX_HTTP_CACHE)
0385     ngx_http_cache_t                 *cache;
0386 #endif
0387 
0388     ngx_http_upstream_t              *upstream;
0389     ngx_array_t                      *upstream_states;
0390                                          /* of ngx_http_upstream_state_t */
0391 
0392     ngx_pool_t                       *pool;
0393     ngx_buf_t                        *header_in;
0394 
0395     ngx_http_headers_in_t             headers_in;
0396     ngx_http_headers_out_t            headers_out;
0397 
0398     ngx_http_request_body_t          *request_body;
0399 
0400     time_t                            lingering_time;
0401     time_t                            start_sec;
0402     ngx_msec_t                        start_msec;
0403 
0404     ngx_uint_t                        method;
0405     ngx_uint_t                        http_version;
0406 
0407     ngx_str_t                         request_line;
0408     ngx_str_t                         uri;
0409     ngx_str_t                         args;
0410     ngx_str_t                         exten;
0411     ngx_str_t                         unparsed_uri;
0412 
0413     ngx_str_t                         method_name;
0414     ngx_str_t                         http_protocol;
0415 
0416     ngx_chain_t                      *out;
0417     ngx_http_request_t               *main;
0418     ngx_http_request_t               *parent;
0419     ngx_http_postponed_request_t     *postponed;
0420     ngx_http_post_subrequest_t       *post_subrequest;
0421     ngx_http_posted_request_t        *posted_requests;
0422 
0423     ngx_int_t                         phase_handler;
0424     ngx_http_handler_pt               content_handler;
0425     ngx_uint_t                        access_code;
0426 
0427     ngx_http_variable_value_t        *variables;
0428 
0429 #if (NGX_PCRE)
0430     ngx_uint_t                        ncaptures;
0431     int                              *captures;
0432     u_char                           *captures_data;
0433 #endif
0434 
0435     size_t                            limit_rate;
0436     size_t                            limit_rate_after;
0437 
0438     /* used to learn the Apache compatible response length without a header */
0439     size_t                            header_size;
0440 
0441     off_t                             request_length;
0442 
0443     ngx_uint_t                        err_status;
0444 
0445     ngx_http_connection_t            *http_connection;
0446     ngx_http_v2_stream_t             *stream;
0447 
0448     ngx_http_log_handler_pt           log_handler;
0449 
0450     ngx_http_cleanup_t               *cleanup;
0451 
0452     unsigned                          count:16;
0453     unsigned                          subrequests:8;
0454     unsigned                          blocked:8;
0455 
0456     unsigned                          aio:1;
0457 
0458     unsigned                          http_state:4;
0459 
0460     /* URI with "/." and on Win32 with "//" */
0461     unsigned                          complex_uri:1;
0462 
0463     /* URI with "%" */
0464     unsigned                          quoted_uri:1;
0465 
0466     /* URI with "+" */
0467     unsigned                          plus_in_uri:1;
0468 
0469     /* URI with " " */
0470     unsigned                          space_in_uri:1;
0471 
0472     unsigned                          invalid_header:1;
0473 
0474     unsigned                          add_uri_to_alias:1;
0475     unsigned                          valid_location:1;
0476     unsigned                          valid_unparsed_uri:1;
0477     unsigned                          uri_changed:1;
0478     unsigned                          uri_changes:4;
0479 
0480     unsigned                          request_body_in_single_buf:1;
0481     unsigned                          request_body_in_file_only:1;
0482     unsigned                          request_body_in_persistent_file:1;
0483     unsigned                          request_body_in_clean_file:1;
0484     unsigned                          request_body_file_group_access:1;
0485     unsigned                          request_body_file_log_level:3;
0486     unsigned                          request_body_no_buffering:1;
0487 
0488     unsigned                          subrequest_in_memory:1;
0489     unsigned                          waited:1;
0490 
0491 #if (NGX_HTTP_CACHE)
0492     unsigned                          cached:1;
0493 #endif
0494 
0495 #if (NGX_HTTP_GZIP)
0496     unsigned                          gzip_tested:1;
0497     unsigned                          gzip_ok:1;
0498     unsigned                          gzip_vary:1;
0499 #endif
0500 
0501     unsigned                          proxy:1;
0502     unsigned                          bypass_cache:1;
0503     unsigned                          no_cache:1;
0504 
0505     /*
0506      * instead of using the request context data in
0507      * ngx_http_limit_conn_module and ngx_http_limit_req_module
0508      * we use the single bits in the request structure
0509      */
0510     unsigned                          limit_conn_set:1;
0511     unsigned                          limit_req_set:1;
0512 
0513 #if 0
0514     unsigned                          cacheable:1;
0515 #endif
0516 
0517     unsigned                          pipeline:1;
0518     unsigned                          chunked:1;
0519     unsigned                          header_only:1;
0520     unsigned                          expect_trailers:1;
0521     unsigned                          keepalive:1;
0522     unsigned                          lingering_close:1;
0523     unsigned                          discard_body:1;
0524     unsigned                          reading_body:1;
0525     unsigned                          internal:1;
0526     unsigned                          error_page:1;
0527     unsigned                          filter_finalize:1;
0528     unsigned                          post_action:1;
0529     unsigned                          request_complete:1;
0530     unsigned                          request_output:1;
0531     unsigned                          header_sent:1;
0532     unsigned                          expect_tested:1;
0533     unsigned                          root_tested:1;
0534     unsigned                          done:1;
0535     unsigned                          logged:1;
0536 
0537     unsigned                          buffered:4;
0538 
0539     unsigned                          main_filter_need_in_memory:1;
0540     unsigned                          filter_need_in_memory:1;
0541     unsigned                          filter_need_temporary:1;
0542     unsigned                          preserve_body:1;
0543     unsigned                          allow_ranges:1;
0544     unsigned                          subrequest_ranges:1;
0545     unsigned                          single_range:1;
0546     unsigned                          disable_not_modified:1;
0547     unsigned                          stat_reading:1;
0548     unsigned                          stat_writing:1;
0549     unsigned                          stat_processing:1;
0550 
0551     unsigned                          background:1;
0552     unsigned                          health_check:1;
0553 
0554     /* used to parse HTTP headers */
0555 
0556     ngx_uint_t                        state;
0557 
0558     ngx_uint_t                        header_hash;
0559     ngx_uint_t                        lowcase_index;
0560     u_char                            lowcase_header[NGX_HTTP_LC_HEADER_LEN];
0561 
0562     u_char                           *header_name_start;
0563     u_char                           *header_name_end;
0564     u_char                           *header_start;
0565     u_char                           *header_end;
0566 
0567     /*
0568      * a memory that can be reused after parsing a request line
0569      * via ngx_http_ephemeral_t
0570      */
0571 
0572     u_char                           *uri_start;
0573     u_char                           *uri_end;
0574     u_char                           *uri_ext;
0575     u_char                           *args_start;
0576     u_char                           *request_start;
0577     u_char                           *request_end;
0578     u_char                           *method_end;
0579     u_char                           *schema_start;
0580     u_char                           *schema_end;
0581     u_char                           *host_start;
0582     u_char                           *host_end;
0583     u_char                           *port_start;
0584     u_char                           *port_end;
0585 
0586     unsigned                          http_minor:16;
0587     unsigned                          http_major:16;
0588 };
0589 
0590 
0591 typedef struct {
0592     ngx_http_posted_request_t         terminal_posted_request;
0593 } ngx_http_ephemeral_t;
0594 
0595 
0596 #define ngx_http_ephemeral(r)  (void *) (&r->uri_start)
0597 
0598 
0599 extern ngx_http_header_t       ngx_http_headers_in[];
0600 extern ngx_http_header_out_t   ngx_http_headers_out[];
0601 
0602 
0603 #define ngx_http_set_log_request(log, r)                                      \
0604     ((ngx_http_log_ctx_t *) log->data)->current_request = r
0605 
0606 
0607 #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */