2
0
Fork 0
lighttpd2/src/connection.h

113 lines
3.2 KiB
C
Raw Normal View History

#ifndef _LIGHTTPD_CONNECTION_H_
#define _LIGHTTPD_CONNECTION_H_
2008-08-05 15:08:32 +00:00
#include "base.h"
typedef enum {
/** unused */
CON_STATE_DEAD,
/** waiting for new input after first request */
CON_STATE_KEEP_ALIVE,
2008-08-06 18:46:42 +00:00
/** after the connect, the request is initialized, keep-alive starts here again */
CON_STATE_REQUEST_START,
/** loop in the read-request-header until the full header is received */
CON_STATE_READ_REQUEST_HEADER,
/** validate the request-header */
CON_STATE_VALIDATE_REQUEST_HEADER,
/** find a handler for the request; there are two ways to produce responses:
* - direct response: for things like errors/auth/redirect
* just set the status code, perhaps fill in some headers,
* append your content (if any) to the queue and do:
* connection_handle_direct(con);
2008-08-06 18:46:42 +00:00
* this moves into the CON_STATE_HANDLE_RESPONSE_HEADER
* request body gets dropped
* - indirect response: you register your plugin as the content handler:
* connection_handle_indirect(con, plugin);
2008-08-06 18:46:42 +00:00
* this moves into the CON_STATE_READ_REQUEST_CONTENT state automatically
* as soon as you build the response headers (e.g. from a backend),
* change to the CON_STATE_HANDLE_RESPONSE_HEADER state:
* connection_set_state(con, CON_STATE_HANDLE_RESPONSE_HEADER);
2008-08-06 18:46:42 +00:00
*/
CON_STATE_HANDLE_REQUEST_HEADER,
/** start forwarding the request content to the handler;
* any filter for the request content must register before a handler
* for the response content registers
*/
CON_STATE_READ_REQUEST_CONTENT,
/** response headers available; this is were compress/deflate should register
* their response content filters
* if all actions are done (or one returns HANDLER_FINISHED) we start
* writing the response content
*/
CON_STATE_HANDLE_RESPONSE_HEADER,
/** start sending content */
CON_STATE_WRITE_RESPONSE,
/** successful request, connection closed - final state */
CON_STATE_RESPONSE_END,
/** connection reset by peer - final state */
CON_STATE_CLOSE,
/** fatal error, connection closed - final state */
CON_STATE_ERROR
2008-08-05 15:08:32 +00:00
} connection_state_t;
struct connection {
2008-08-05 15:08:32 +00:00
guint idx; /** index in connection table */
server *srv;
worker *wrk;
2008-08-05 15:08:32 +00:00
connection_state_t state;
2008-08-06 23:44:09 +00:00
gboolean response_headers_sent, expect_100_cont;
2008-08-05 15:08:32 +00:00
chunkqueue *raw_in, *raw_out;
chunkqueue *in, *out;
ev_io sock_watcher;
2008-07-25 22:42:08 +00:00
sock_addr remote_addr, local_addr;
GString *remote_addr_str, *local_addr_str;
2008-08-06 18:46:42 +00:00
gboolean is_ssl, keep_alive;
action_stack action_stack;
option_value *options;
request request;
physical physical;
2008-08-06 18:46:42 +00:00
response response;
http_request_ctx req_parser_ctx;
2008-08-06 18:46:42 +00:00
plugin *content_handler;
struct log_t *log;
gint log_level;
/* Keep alive timeout data */
struct {
GList *link;
ev_tstamp timeout;
2008-08-17 19:27:09 +00:00
guint max_idle;
ev_timer watcher;
} keep_alive_data;
};
LI_API connection* connection_new(worker *wrk);
LI_API void connection_reset(connection *con);
LI_API void connection_free(connection *con);
2008-08-05 15:08:32 +00:00
LI_API void connection_set_state(connection *con, connection_state_t state);
LI_API void connection_state_machine(connection *con);
2008-08-06 18:46:42 +00:00
LI_API void connection_handle_direct(connection *con);
LI_API void connection_handle_indirect(connection *con, plugin *p);
2008-08-05 15:08:32 +00:00
#endif