xref: /lighttpd1.4/src/request.h (revision 34709192)
1 #ifndef _REQUEST_H_
2 #define _REQUEST_H_
3 #include "first.h"
4 
5 #include <time.h>       /* (struct timespec) */
6 
7 #include "base_decls.h"
8 #include "buffer.h"
9 #include "array.h"
10 #include "http_kv.h"
11 
12 struct log_error_st;    /* declaration */
13 struct chunkqueue;      /* declaration */
14 struct cond_cache_t;    /* declaration */
15 struct cond_match_t;    /* declaration */
16 
17 typedef struct {
18     unsigned int http_parseopts;
19     uint32_t max_request_field_size;
20     const array *mimetypes;
21 
22     /* virtual-servers */
23     const buffer *document_root;
24     const buffer *server_name;
25     const buffer *server_tag;
26     struct log_error_st *errh;
27 
28     unsigned int max_request_size;
29     unsigned short max_keep_alive_requests;
30     unsigned short max_keep_alive_idle;
31     unsigned short max_read_idle;
32     unsigned short max_write_idle;
33     unsigned short stream_request_body;
34     unsigned short stream_response_body;
35     unsigned char high_precision_timestamps;
36     unsigned char allow_http11;
37     unsigned char follow_symlink;
38     unsigned char etag_flags;
39     unsigned char force_lowercase_filenames; /*(case-insensitive file systems)*/
40     unsigned char use_xattr;
41     unsigned char range_requests;
42     unsigned char error_intercept;
43 
44     /* debug */
45     unsigned char log_file_not_found;
46     unsigned char log_request_header;
47     unsigned char log_request_handling;
48     unsigned char log_response_header;
49     unsigned char log_condition_handling;
50     unsigned char log_timeouts;
51     unsigned char log_state_handling;
52     unsigned char log_request_header_on_error;
53 
54     unsigned int bytes_per_second; /* connection bytes/sec limit */
55     unsigned int global_bytes_per_second;/*total bytes/sec limit for scope*/
56 
57     /* server-wide traffic-shaper
58      *
59      * each context has the counter which is inited once
60      * a second by the global_bytes_per_second config-var
61      *
62      * as soon as global_bytes_per_second gets below 0
63      * the connected conns are "offline" a little bit
64      *
65      * the problem:
66      * we somehow have to lose our "we are writable" signal on the way.
67      *
68      */
69     off_t *global_bytes_per_second_cnt_ptr; /*  */
70 
71     const buffer *error_handler;
72     const buffer *error_handler_404;
73     const buffer *errorfile_prefix;
74     struct log_error_st *serrh; /* script errh */
75 } request_config;
76 
77 typedef struct {
78     buffer scheme; /* scheme without colon or slashes ( "http" or "https" ) */
79 
80     /* authority with optional portnumber ("site.name" or "site.name:8080" ) NOTE: without "username:password@" */
81     buffer authority;
82 
83     /* path including leading slash ("/" or "/index.html") - urldecoded, and sanitized  ( buffer_path_simplify() && buffer_urldecode_path() ) */
84     buffer path;
85     buffer query; /* querystring ( everything after "?", ie: in "/index.php?foo=1", query is "foo=1" ) */
86 } request_uri;
87 
88 typedef struct {
89     buffer path;
90     buffer basedir; /* path = "(basedir)(.*)" */
91 
92     buffer doc_root; /* path = doc_root + rel_path */
93     buffer rel_path;
94 
95     buffer etag;
96 } physical;
97 
98 typedef struct {
99     off_t gw_chunked;
100     buffer b;
101     int done;
102 } response_dechunk;
103 
104 /* the order of the items should be the same as they are processed
105  * read before write as we use this later e.g. <= CON_STATE_REQUEST_END */
106 typedef enum {
107     CON_STATE_CONNECT,
108     CON_STATE_REQUEST_START,
109     CON_STATE_READ,
110     CON_STATE_REQUEST_END,
111     CON_STATE_READ_POST,
112     CON_STATE_HANDLE_REQUEST,
113     CON_STATE_RESPONSE_START,
114     CON_STATE_WRITE,
115     CON_STATE_RESPONSE_END,
116     CON_STATE_ERROR,
117     CON_STATE_CLOSE
118 } request_state_t;
119 
120 struct request_st {
121     request_state_t state; /*(modules should not modify request state)*/
122     int http_status;
123 
124     http_method_t http_method;
125     http_version_t http_version;
126 
127     const plugin *handler_module;
128     void **plugin_ctx;           /* plugin connection specific config */
129     connection *con;
130 
131     /* config conditions (internal) */
132     uint32_t conditional_is_valid;
133     struct cond_cache_t *cond_cache;
134     struct cond_match_t *cond_match;
135 
136     request_config conf;
137 
138     /* request */
139     uint32_t rqst_htags;/* bitfield of flagged headers present in request */
140     uint32_t rqst_header_len;
141     array rqst_headers;
142 
143     request_uri uri;
144     physical physical;
145     array env; /* used to pass lighttpd internal stuff */
146 
147     off_t reqbody_length; /* request Content-Length */
148     off_t te_chunked;
149     struct chunkqueue *reqbody_queue; /*(might use tempfiles)*/
150 
151     buffer *http_host; /* copy of array value buffer ptr; not alloc'ed */
152     const buffer *server_name;
153 
154     buffer target;
155     buffer target_orig;
156 
157     buffer pathinfo;
158     buffer server_name_buf;
159 
160     /* response */
161     off_t content_length;
162     uint32_t resp_htags; /*bitfield of flagged headers present in response*/
163     uint32_t resp_header_len;
164     array resp_headers;
165     char resp_body_finished;
166     char resp_body_started;
167     char resp_send_chunked;
168     char resp_decode_chunked;
169 
170     char loops_per_request;  /* catch endless loops in a single request */
171     char keep_alive; /* only request.c can enable it, all other just disable */
172     char async_callback;
173 
174     struct chunkqueue *write_queue;     /* HTTP response queue [ file, mem ] */
175     struct chunkqueue *read_queue;      /* HTTP request queue  [ mem ] */
176     buffer *tmp_buf;                    /* shared; same as srv->tmp_buf */
177     response_dechunk *gw_dechunk;
178 
179     struct timespec start_hp;
180     time_t start_ts;
181 
182     int error_handler_saved_status; /* error-handler */
183     http_method_t error_handler_saved_method; /* error-handler */
184 };
185 
186 
187 int http_request_parse(request_st * restrict r, char * restrict hdrs, const unsigned short * restrict hloffsets, int scheme_port);
188 int http_request_parse_target(request_st *r, int scheme_port);
189 int http_request_host_normalize(buffer *b, int scheme_port);
190 int http_request_host_policy(buffer *b, unsigned int http_parseopts, int scheme_port);
191 
192 #endif
193