2002-08-07 00:39:45 +08:00
|
|
|
#ifndef _NGX_HTTP_H_INCLUDED_
|
|
|
|
#define _NGX_HTTP_H_INCLUDED_
|
|
|
|
|
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_types.h>
|
2002-12-03 00:09:40 +08:00
|
|
|
#include <ngx_string.h>
|
|
|
|
#include <ngx_table.h>
|
2002-08-30 00:59:54 +08:00
|
|
|
#include <ngx_hunk.h>
|
2002-09-02 22:48:24 +08:00
|
|
|
#include <ngx_files.h>
|
2002-08-07 00:39:45 +08:00
|
|
|
#include <ngx_connection.h>
|
2002-12-19 15:08:55 +08:00
|
|
|
#include <ngx_config_file.h>
|
2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
|
2002-12-11 02:05:12 +08:00
|
|
|
#define NGX_HTTP_VERSION_10 1000
|
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
#define NGX_HTTP_GET 1
|
|
|
|
#define NGX_HTTP_HEAD 2
|
|
|
|
#define NGX_HTTP_POST 3
|
|
|
|
|
|
|
|
#define NGX_HTTP_CONN_CLOSE 0
|
|
|
|
#define NGX_HTTP_CONN_KEEP_ALIVE 1
|
|
|
|
|
2002-08-30 00:59:54 +08:00
|
|
|
|
2002-09-13 22:47:42 +08:00
|
|
|
#define NGX_HTTP_PARSE_HEADER_DONE 1
|
|
|
|
#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_HEAD 13
|
|
|
|
#define NGX_HTTP_PARSE_INVALID_HEADER 14
|
2002-08-30 00:59:54 +08:00
|
|
|
|
2002-08-16 23:27:03 +08:00
|
|
|
|
|
|
|
#define NGX_HTTP_OK 200
|
2002-09-02 22:48:24 +08:00
|
|
|
#define NGX_HTTP_SPECIAL_RESPONSE 300
|
2002-12-15 14:25:09 +08:00
|
|
|
#define NGX_HTTP_MOVED_PERMANENTLY 301
|
|
|
|
#define NGX_HTTP_MOVED_TEMPORARILY 302
|
|
|
|
#define NGX_HTTP_NOT_MODIFIED 304
|
2002-08-30 00:59:54 +08:00
|
|
|
#define NGX_HTTP_BAD_REQUEST 400
|
2002-08-16 23:27:03 +08:00
|
|
|
#define NGX_HTTP_NOT_FOUND 404
|
2002-09-13 22:47:42 +08:00
|
|
|
#define NGX_HTTP_REQUEST_URI_TOO_LARGE 414
|
2002-12-15 14:25:09 +08:00
|
|
|
#define NGX_HTTP_INTERNAL_SERVER_ERROR 500
|
2002-08-16 23:27:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define NGX_HTTP_STATIC_HANDLER 0
|
|
|
|
#define NGX_HTTP_DIRECTORY_HANDLER 1
|
2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
|
2002-08-16 01:20:26 +08:00
|
|
|
|
2002-08-16 23:27:03 +08:00
|
|
|
typedef struct {
|
2002-08-30 00:59:54 +08:00
|
|
|
char *doc_root;
|
|
|
|
size_t doc_root_len;
|
2002-09-02 22:48:24 +08:00
|
|
|
|
2002-09-16 23:01:44 +08:00
|
|
|
size_t connection_pool_size;
|
2002-09-02 22:48:24 +08:00
|
|
|
size_t request_pool_size;
|
|
|
|
|
|
|
|
size_t header_buffer_size;
|
|
|
|
size_t discarded_buffer_size;
|
2002-08-30 00:59:54 +08:00
|
|
|
|
2002-09-16 23:01:44 +08:00
|
|
|
ngx_msec_t header_timeout;
|
|
|
|
ngx_msec_t lingering_timeout;
|
|
|
|
time_t lingering_time;
|
2002-08-16 23:27:03 +08:00
|
|
|
} ngx_http_server_t;
|
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
|
2002-12-03 00:09:40 +08:00
|
|
|
typedef struct {
|
|
|
|
int len;
|
|
|
|
char *data;
|
|
|
|
int offset;
|
|
|
|
} ngx_http_header_t;
|
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
|
2002-12-03 00:09:40 +08:00
|
|
|
typedef struct {
|
|
|
|
ngx_table_elt_t *host;
|
|
|
|
ngx_table_elt_t *connection;
|
2002-12-15 14:25:09 +08:00
|
|
|
ngx_table_elt_t *if_modified_since;
|
2002-12-03 00:09:40 +08:00
|
|
|
ngx_table_elt_t *user_agent;
|
|
|
|
ngx_table_elt_t *accept_encoding;
|
|
|
|
|
|
|
|
ngx_table_t *headers;
|
|
|
|
} ngx_http_headers_in_t;
|
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
typedef struct {
|
2002-12-11 02:05:12 +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;
|
|
|
|
ngx_table_elt_t *location;
|
|
|
|
ngx_table_elt_t *last_modified;
|
|
|
|
|
|
|
|
ngx_table_t *headers;
|
|
|
|
|
|
|
|
off_t content_length;
|
|
|
|
char *charset;
|
|
|
|
char *etag;
|
|
|
|
time_t date_time;
|
|
|
|
time_t last_modified_time;
|
2002-08-20 22:48:28 +08:00
|
|
|
} ngx_http_headers_out_t;
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
typedef struct ngx_http_request_s ngx_http_request_t;
|
|
|
|
|
|
|
|
struct ngx_http_request_s {
|
2002-12-15 14:25:09 +08:00
|
|
|
ngx_file_t file;
|
2002-12-11 02:05:12 +08:00
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
#if 0
|
|
|
|
ngx_str_t filename;
|
|
|
|
ngx_file_info_t fileinfo;
|
2002-08-26 23:18:19 +08:00
|
|
|
ngx_fd_t fd;
|
2002-12-15 14:25:09 +08:00
|
|
|
int filename_len;
|
|
|
|
#endif
|
2002-08-20 22:48:28 +08:00
|
|
|
|
2002-09-07 18:14:25 +08:00
|
|
|
void **ctx;
|
|
|
|
void **loc_conf;
|
|
|
|
void **srv_conf;
|
|
|
|
|
2002-08-30 00:59:54 +08:00
|
|
|
ngx_pool_t *pool;
|
|
|
|
ngx_hunk_t *header_in;
|
|
|
|
|
2002-12-03 00:09:40 +08:00
|
|
|
ngx_http_headers_in_t headers_in;
|
|
|
|
ngx_http_headers_out_t headers_out;
|
2002-08-16 23:27:03 +08:00
|
|
|
|
|
|
|
int (*handler)(ngx_http_request_t *r);
|
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
int method;
|
|
|
|
|
2002-09-12 22:42:29 +08:00
|
|
|
time_t lingering_time;
|
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
int http_version;
|
|
|
|
int http_major;
|
|
|
|
int http_minor;
|
|
|
|
|
2002-12-03 23:45:38 +08:00
|
|
|
ngx_str_t request_line;
|
2002-12-11 02:05:12 +08:00
|
|
|
ngx_str_t uri;
|
|
|
|
ngx_str_t exten;
|
2002-08-07 00:39:45 +08:00
|
|
|
ngx_http_request_t *main;
|
|
|
|
|
2002-08-16 23:27:03 +08:00
|
|
|
ngx_connection_t *connection;
|
|
|
|
ngx_http_server_t *server;
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2002-08-22 23:24:03 +08:00
|
|
|
int filter;
|
|
|
|
|
2002-09-02 22:48:24 +08:00
|
|
|
ssize_t client_content_length;
|
|
|
|
char *discarded_buffer;
|
|
|
|
|
2002-09-12 22:42:29 +08:00
|
|
|
unsigned keepalive:1;
|
|
|
|
unsigned lingering_close:1;
|
|
|
|
|
2002-09-16 23:01:44 +08:00
|
|
|
unsigned header_read:1;
|
2002-09-13 22:47:42 +08:00
|
|
|
unsigned header_timeout:1;
|
|
|
|
|
|
|
|
unsigned logging:1;
|
2002-08-30 00:59:54 +08:00
|
|
|
|
2002-08-20 22:48:28 +08:00
|
|
|
unsigned header_only:1;
|
2002-10-05 01:58:04 +08:00
|
|
|
unsigned unusual_uri:1; /* URI is not started with '/' - "GET http://" */
|
2002-12-15 14:25:09 +08:00
|
|
|
unsigned complex_uri:1; /* URI with "/." or with "//" (WIN32) */
|
2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
int state;
|
|
|
|
char *uri_start;
|
|
|
|
char *uri_end;
|
|
|
|
char *uri_ext;
|
|
|
|
char *args_start;
|
2002-10-05 01:58:04 +08:00
|
|
|
char *request_end;
|
2002-08-07 00:39:45 +08:00
|
|
|
char *header_name_start;
|
|
|
|
char *header_name_end;
|
|
|
|
char *header_start;
|
|
|
|
char *header_end;
|
|
|
|
#ifdef NGX_EVENT
|
|
|
|
int (*state_handler)(ngx_http_request_t *r);
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
|
2002-08-26 23:18:19 +08:00
|
|
|
typedef struct {
|
|
|
|
char *action;
|
|
|
|
char *client;
|
|
|
|
char *url;
|
|
|
|
} ngx_http_log_ctx_t;
|
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2002-09-07 18:14:25 +08:00
|
|
|
typedef struct {
|
2002-09-11 23:18:33 +08:00
|
|
|
int index;
|
2002-12-11 02:05:12 +08:00
|
|
|
|
2002-09-11 23:18:33 +08:00
|
|
|
void *(*create_srv_conf)(ngx_pool_t *p);
|
|
|
|
void *(*create_loc_conf)(ngx_pool_t *p);
|
|
|
|
ngx_command_t *commands;
|
2002-12-11 02:05:12 +08:00
|
|
|
|
2002-09-11 23:18:33 +08:00
|
|
|
int (*init_module)(ngx_pool_t *p);
|
2002-12-11 02:05:12 +08:00
|
|
|
|
|
|
|
int (*translate_handler)(ngx_http_request_t *r);
|
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
int (*output_header_filter) (ngx_http_request_t *r);
|
|
|
|
int (*next_output_header_filter) (ngx_http_request_t *r);
|
|
|
|
|
|
|
|
int (*output_body_filter)();
|
|
|
|
int (*next_output_body_filter)
|
|
|
|
(ngx_http_request_t *r, ngx_chain_t *ch);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
int (*next_output_body_filter)(int (**next_filter)
|
2002-09-11 23:18:33 +08:00
|
|
|
(ngx_http_request_t *r, ngx_chain_t *ch));
|
2002-12-15 14:25:09 +08:00
|
|
|
#endif
|
2002-09-07 18:14:25 +08:00
|
|
|
} ngx_http_module_t;
|
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
|
2002-09-07 18:14:25 +08:00
|
|
|
#define NGX_HTTP_MODULE 0
|
|
|
|
|
|
|
|
#define ngx_get_module_loc_conf(r, module) r->loc_conf[module.index]
|
|
|
|
#define ngx_get_module_ctx(r, module) r->ctx[module.index]
|
|
|
|
|
2002-12-03 00:09:40 +08:00
|
|
|
#define ngx_http_create_ctx(r, cx, module, size) \
|
2002-09-11 23:18:33 +08:00
|
|
|
do { \
|
2002-12-03 00:09:40 +08:00
|
|
|
ngx_test_null(cx, ngx_pcalloc(r->pool, size), NGX_ERROR); \
|
|
|
|
r->ctx[module.index] = cx; \
|
2002-09-11 23:18:33 +08:00
|
|
|
} while (0)
|
|
|
|
|
2002-09-07 18:14:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* STUB */
|
2002-08-07 00:39:45 +08:00
|
|
|
#define NGX_INDEX "index.html"
|
|
|
|
|
|
|
|
|
2002-09-02 22:48:24 +08:00
|
|
|
/* STUB */
|
|
|
|
int ngx_http_init(ngx_pool_t *pool, ngx_log_t *log);
|
2002-12-15 14:25:09 +08:00
|
|
|
/**/
|
2002-09-02 22:48:24 +08:00
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
int ngx_http_init_connection(ngx_connection_t *c);
|
|
|
|
|
|
|
|
|
2002-12-15 14:25:09 +08:00
|
|
|
int ngx_http_discard_body(ngx_http_request_t *r);
|
|
|
|
|
|
|
|
|
2002-09-11 23:18:33 +08:00
|
|
|
extern int ngx_max_module;
|
|
|
|
|
|
|
|
extern ngx_http_module_t *ngx_http_modules[];
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
#endif /* _NGX_HTTP_H_INCLUDED_ */
|