nginx/src/http/ngx_http_request.h

293 lines
7.9 KiB
C
Raw Normal View History

2003-05-20 00:39:14 +08:00
#ifndef _NGX_HTTP_REQUEST_H_INCLUDED_
#define _NGX_HTTP_REQUEST_H_INCLUDED_
2004-03-16 15:10:12 +08:00
#define NGX_HTTP_VERSION_9 9
#define NGX_HTTP_VERSION_10 1000
#define NGX_HTTP_VERSION_11 1001
2003-05-20 00:39:14 +08:00
2004-03-16 15:10:12 +08:00
#define NGX_HTTP_GET 1
#define NGX_HTTP_HEAD 2
#define NGX_HTTP_POST 3
2003-05-20 00:39:14 +08:00
2004-03-16 15:10:12 +08:00
#define NGX_HTTP_CONNECTION_CLOSE 1
#define NGX_HTTP_CONNECTION_KEEP_ALIVE 2
2003-05-20 00:39:14 +08:00
2004-03-16 15:10:12 +08:00
#define NGX_NONE 1
2003-10-08 23:32:54 +08:00
2004-03-16 15:10:12 +08:00
#define NGX_HTTP_PARSE_HEADER_DONE 1
2003-10-27 16:53:49 +08:00
2004-03-16 15:10:12 +08:00
#define NGX_HTTP_CLIENT_ERROR 10
#define NGX_HTTP_PARSE_INVALID_METHOD 10
#define NGX_HTTP_PARSE_INVALID_REQUEST 11
#define NGX_HTTP_PARSE_TOO_LONG_URI 12
#define NGX_HTTP_PARSE_INVALID_09_METHOD 13
2003-10-27 16:53:49 +08:00
2004-03-16 15:10:12 +08:00
#define NGX_HTTP_PARSE_HEADER_ERROR 14
#define NGX_HTTP_PARSE_INVALID_HEADER 14
#define NGX_HTTP_PARSE_TOO_LONG_HEADER 15
#define NGX_HTTP_PARSE_NO_HOST_HEADER 16
#define NGX_HTTP_PARSE_INVALID_CL_HEADER 17
2003-05-20 00:39:14 +08:00
2003-10-28 05:01:00 +08:00
#define NGX_HTTP_OK 200
#define NGX_HTTP_PARTIAL_CONTENT 206
#define NGX_HTTP_SPECIAL_RESPONSE 300
#define NGX_HTTP_MOVED_PERMANENTLY 301
#define NGX_HTTP_MOVED_TEMPORARILY 302
#define NGX_HTTP_NOT_MODIFIED 304
#define NGX_HTTP_BAD_REQUEST 400
#define NGX_HTTP_FORBIDDEN 403
#define NGX_HTTP_NOT_FOUND 404
#define NGX_HTTP_NOT_ALLOWED 405
#define NGX_HTTP_REQUEST_TIME_OUT 408
#define NGX_HTTP_REQUEST_ENTITY_TOO_LARGE 413
#define NGX_HTTP_REQUEST_URI_TOO_LARGE 414
#define NGX_HTTP_RANGE_NOT_SATISFIABLE 416
2003-11-19 00:49:00 +08:00
/*
2004-01-19 05:09:21 +08:00
* HTTP does not define the code for the case when a client closed
* the connection while we are processing its request so we introduce
* own code to log such situation when a client has closed the connection
* before we even try to send the HTTP header to it
2003-11-19 00:49:00 +08:00
*/
2003-11-19 05:34:08 +08:00
#define NGX_HTTP_CLIENT_CLOSED_REQUEST 499
2003-11-19 00:49:00 +08:00
2003-10-28 05:01:00 +08:00
#define NGX_HTTP_INTERNAL_SERVER_ERROR 500
#define NGX_HTTP_NOT_IMPLEMENTED 501
#define NGX_HTTP_BAD_GATEWAY 502
#define NGX_HTTP_SERVICE_UNAVAILABLE 503
#define NGX_HTTP_GATEWAY_TIME_OUT 504
2003-05-20 00:39:14 +08:00
2003-12-26 04:26:58 +08:00
typedef enum {
NGX_HTTP_INITING_REQUEST_STATE = 0,
NGX_HTTP_READING_REQUEST_STATE,
NGX_HTTP_PROCESS_REQUEST_STATE,
2003-05-20 00:39:14 +08:00
2003-12-26 04:26:58 +08:00
NGX_HTTP_CONNECT_UPSTREAM_STATE,
NGX_HTTP_WRITING_UPSTREAM_STATE,
NGX_HTTP_READING_UPSTREAM_STATE,
NGX_HTTP_WRITING_REQUEST_STATE,
NGX_HTTP_LINGERING_CLOSE_STATE,
NGX_HTTP_KEEPALIVE_STATE
} ngx_http_state_e;
2003-05-20 00:39:14 +08:00
typedef struct {
2004-03-16 15:10:12 +08:00
ngx_str_t name;
ngx_uint_t offset;
2003-05-20 00:39:14 +08:00
} ngx_http_header_t;
typedef struct {
2004-03-23 14:01:52 +08:00
ngx_table_t headers; /* it must be first field */
2003-10-29 16:30:44 +08:00
2003-05-20 00:39:14 +08:00
ngx_table_elt_t *host;
ngx_table_elt_t *connection;
ngx_table_elt_t *if_modified_since;
2003-10-23 00:38:26 +08:00
ngx_table_elt_t *user_agent;
ngx_table_elt_t *referer;
2003-10-23 00:38:26 +08:00
ngx_table_elt_t *content_length;
2004-03-13 00:57:08 +08:00
2003-10-23 00:38:26 +08:00
ngx_table_elt_t *range;
2003-05-20 00:39:14 +08:00
2004-03-13 00:57:08 +08:00
#if (NGX_HTTP_GZIP)
ngx_table_elt_t *accept_encoding;
#endif
2003-11-04 06:20:44 +08:00
ngx_table_elt_t *authorization;
2003-10-21 01:14:07 +08:00
ngx_table_elt_t *keep_alive;
2003-05-20 00:39:14 +08:00
2004-03-13 00:57:08 +08:00
#if (NGX_HTTP_PROXY)
ngx_table_elt_t *x_forwarded_for;
#endif
2003-10-22 00:49:56 +08:00
size_t host_name_len;
ssize_t content_length_n;
size_t connection_type;
ssize_t keep_alive_n;
2003-05-20 00:39:14 +08:00
} ngx_http_headers_in_t;
typedef struct {
ngx_chain_t chain[4];
ngx_hunk_t *header_out;
ngx_hunk_t *hunk;
ngx_hunk_t *file_hunk;
ngx_file_t temp_file;
ngx_path_t *temp_path;
off_t offset;
2004-03-16 15:10:12 +08:00
u_char *header_in_pos;
2003-05-20 00:39:14 +08:00
} ngx_http_request_body_t;
2003-06-02 23:24:30 +08:00
typedef struct {
2004-03-16 15:10:12 +08:00
off_t start;
off_t end;
ngx_str_t content_range;
2003-06-02 23:24:30 +08:00
} ngx_http_range_t;
2003-05-20 00:39:14 +08:00
typedef struct {
2004-03-23 14:01:52 +08:00
ngx_table_t headers; /* it must be first field */
2003-10-29 16:30:44 +08:00
2003-05-20 00:39:14 +08:00
int status;
ngx_str_t status_line;
ngx_table_elt_t *server;
ngx_table_elt_t *date;
ngx_table_elt_t *content_type;
2003-10-22 00:49:56 +08:00
ngx_table_elt_t *content_length;
2003-09-29 03:29:06 +08:00
ngx_table_elt_t *content_encoding;
2003-05-20 00:39:14 +08:00
ngx_table_elt_t *location;
ngx_table_elt_t *last_modified;
2003-06-02 23:24:30 +08:00
ngx_table_elt_t *content_range;
2003-10-02 13:39:37 +08:00
ngx_table_elt_t *accept_ranges;
2003-06-02 23:24:30 +08:00
ngx_str_t charset;
ngx_array_t ranges;
2003-05-20 00:39:14 +08:00
2003-10-22 00:49:56 +08:00
off_t content_length_n;
2004-03-16 15:10:12 +08:00
u_char *etag;
2003-05-20 00:39:14 +08:00
time_t date_time;
time_t last_modified_time;
} ngx_http_headers_out_t;
2003-12-01 04:03:18 +08:00
struct ngx_http_cleanup_s {
2003-11-29 01:41:47 +08:00
union {
struct {
ngx_fd_t fd;
2004-03-16 15:10:12 +08:00
u_char *name;
2003-11-29 01:41:47 +08:00
} file;
struct {
ngx_http_cache_hash_t *hash;
ngx_http_cache_t *cache;
} cache;
} data;
2003-12-01 04:03:18 +08:00
unsigned valid:1;
2003-11-29 01:41:47 +08:00
unsigned cache:1;
2003-12-01 04:03:18 +08:00
};
2003-11-29 01:41:47 +08:00
2003-10-10 23:10:50 +08:00
typedef int (*ngx_http_handler_pt)(ngx_http_request_t *r);
2003-05-20 00:39:14 +08:00
struct ngx_http_request_s {
2003-11-29 01:41:47 +08:00
ngx_connection_t *connection;
2003-05-20 00:39:14 +08:00
2003-11-29 01:41:47 +08:00
void **ctx;
void **main_conf;
void **srv_conf;
void **loc_conf;
2003-05-20 00:39:14 +08:00
2003-11-29 01:41:47 +08:00
ngx_http_cache_t *cache;
2003-11-27 15:45:22 +08:00
2003-05-20 00:39:14 +08:00
ngx_file_t file;
ngx_pool_t *pool;
ngx_hunk_t *header_in;
ngx_http_request_body_t *request_body;
ngx_http_headers_in_t headers_in;
ngx_http_headers_out_t headers_out;
2003-06-02 23:24:30 +08:00
time_t lingering_time;
2003-05-20 00:39:14 +08:00
2004-03-16 15:10:12 +08:00
ngx_uint_t method;
ngx_uint_t http_version;
ngx_uint_t http_major;
ngx_uint_t http_minor;
2003-05-20 00:39:14 +08:00
ngx_str_t request_line;
ngx_str_t uri;
ngx_str_t args;
ngx_str_t exten;
ngx_str_t unparsed_uri;
ngx_http_request_t *main;
2004-03-16 15:10:12 +08:00
uint32_t in_addr;
ngx_uint_t port;
2003-05-27 20:18:54 +08:00
ngx_str_t *port_name; /* ":80" */
ngx_str_t *server_name;
ngx_array_t *virtual_names;
2003-05-20 00:39:14 +08:00
2004-03-16 15:10:12 +08:00
ngx_uint_t phase;
ngx_int_t phase_handler;
2003-10-10 23:10:50 +08:00
ngx_http_handler_pt content_handler;
2003-05-20 00:39:14 +08:00
2003-10-27 16:53:49 +08:00
ngx_temp_file_t *temp_file;
ngx_chain_t *request_hunks;
ngx_hunk_t *request_body_hunk;
2004-03-16 15:10:12 +08:00
size_t request_body_len;
2003-10-27 16:53:49 +08:00
void (*request_body_handler) (void *data);
void *data;
2003-11-29 01:41:47 +08:00
ngx_array_t cleanup;
2003-12-15 04:10:27 +08:00
size_t header_size;
2004-03-16 15:10:12 +08:00
u_char *discarded_buffer;
2003-11-11 05:09:22 +08:00
void **err_ctx;
2004-03-16 15:10:12 +08:00
ngx_uint_t err_status;
2003-05-20 00:39:14 +08:00
2003-12-26 04:26:58 +08:00
unsigned http_state:4;
2003-06-02 23:24:30 +08:00
/* URI is not started with '/' - "GET http://" */
unsigned unusual_uri:1;
/* URI with "/.", "%" and on Win32 with "//" */
unsigned complex_uri:1;
unsigned header_timeout_set:1;
2003-05-20 00:39:14 +08:00
2003-06-02 23:24:30 +08:00
unsigned proxy:1;
2003-11-03 06:56:18 +08:00
unsigned bypass_cache:1;
2003-11-04 06:20:44 +08:00
unsigned no_cache:1;
2003-11-03 06:56:18 +08:00
2003-06-02 23:24:30 +08:00
#if 0
unsigned cachable:1;
2003-05-20 00:39:14 +08:00
#endif
2003-06-02 23:24:30 +08:00
unsigned pipeline:1;
2003-10-22 15:05:29 +08:00
/* can we use sendfile ? */
unsigned sendfile:1;
2003-06-02 23:24:30 +08:00
unsigned chunked:1;
unsigned header_only:1;
unsigned keepalive:1;
unsigned lingering_close:1;
2003-10-10 23:10:50 +08:00
unsigned closed:1;
2003-06-02 23:24:30 +08:00
2004-03-16 15:10:12 +08:00
/* TODO: use the filter flags or the separate bits ???? */
u_int filter;
2003-06-02 23:24:30 +08:00
/* used to parse HTTP headers */
2004-03-16 15:10:12 +08:00
ngx_int_t state;
u_char *uri_start;
u_char *uri_end;
u_char *uri_ext;
u_char *args_start;
u_char *request_start;
u_char *request_end;
u_char *header_name_start;
u_char *header_name_end;
u_char *header_start;
u_char *header_end;
2003-05-20 00:39:14 +08:00
};
2003-10-29 16:30:44 +08:00
extern ngx_http_header_t ngx_http_headers_in[];
extern ngx_http_header_t ngx_http_headers_out[];
2003-05-20 00:39:14 +08:00
#endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */