xref: /lighttpd1.4/src/request.h (revision e11f72b1)
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 /* the order of the items should be the same as they are processed
99  * read before write as we use this later e.g. <= CON_STATE_REQUEST_END */
100 typedef enum {
101     CON_STATE_CONNECT,
102     CON_STATE_REQUEST_START,
103     CON_STATE_READ,
104     CON_STATE_REQUEST_END,
105     CON_STATE_READ_POST,
106     CON_STATE_HANDLE_REQUEST,
107     CON_STATE_RESPONSE_START,
108     CON_STATE_WRITE,
109     CON_STATE_RESPONSE_END,
110     CON_STATE_ERROR,
111     CON_STATE_CLOSE
112 } request_state_t;
113 
114 struct request_st {
115     request_state_t state; /*(modules should not modify request state)*/
116     int http_status;
117 
118     http_method_t http_method;
119     http_version_t http_version;
120 
121     const plugin *handler_module;
122     void **plugin_ctx;           /* plugin connection specific config */
123     connection *con;
124 
125     /* config conditions (internal) */
126     uint32_t conditional_is_valid;
127     struct cond_cache_t *cond_cache;
128     struct cond_match_t *cond_match;
129 
130     request_config conf;
131 
132     /* request */
133     uint32_t rqst_htags;/* bitfield of flagged headers present in request */
134     uint32_t rqst_header_len;
135     array rqst_headers;
136 
137     request_uri uri;
138     physical physical;
139     array env; /* used to pass lighttpd internal stuff */
140 
141     off_t reqbody_length; /* request Content-Length */
142     off_t te_chunked;
143     struct chunkqueue *reqbody_queue; /*(might use tempfiles)*/
144 
145     buffer *http_host; /* copy of array value buffer ptr; not alloc'ed */
146     const buffer *server_name;
147 
148     buffer target;
149     buffer target_orig;
150 
151     buffer pathinfo;
152     buffer server_name_buf;
153 
154     /* response */
155     off_t content_length;
156     uint32_t resp_htags; /*bitfield of flagged headers present in response*/
157     uint32_t resp_header_len;
158     array resp_headers;
159     char resp_body_finished;
160     char resp_body_started;
161     char resp_send_chunked;
162 
163     char loops_per_request;  /* catch endless loops in a single request */
164     char keep_alive; /* only request.c can enable it, all other just disable */
165     char async_callback;
166 
167     struct chunkqueue *write_queue;     /* HTTP response queue [ file, mem ] */
168     struct chunkqueue *read_queue;      /* HTTP request queue  [ mem ] */
169     buffer *tmp_buf;                    /* shared; same as srv->tmp_buf */
170 
171     struct timespec start_hp;
172     time_t start_ts;
173 
174     int error_handler_saved_status; /* error-handler */
175     http_method_t error_handler_saved_method; /* error-handler */
176 };
177 
178 
179 int http_request_parse(request_st * restrict r, char * restrict hdrs, const unsigned short * restrict hloffsets, int scheme_port);
180 int http_request_parse_target(request_st *r, int scheme_port);
181 int http_request_host_normalize(buffer *b, int scheme_port);
182 int http_request_host_policy(buffer *b, unsigned int http_parseopts, int scheme_port);
183 
184 #endif
185