1 /* $NetBSD: http-internal.h,v 1.1.1.2 2013/04/11 16:43:24 christos Exp $ */
3 * Copyright 2001-2007 Niels Provos <provos@citi.umich.edu>
4 * Copyright 2007-2012 Niels Provos and Nick Mathewson
6 * This header file contains definitions for dealing with HTTP requests
7 * that are internal to libevent. As user of the library, you should not
8 * need to know about these.
11 #ifndef _HTTP_INTERNAL_H_
12 #define _HTTP_INTERNAL_H_
14 #include "event2/event_struct.h"
15 #include "util-internal.h"
16 #include "defer-internal.h"
18 #define HTTP_CONNECT_TIMEOUT 45
19 #define HTTP_WRITE_TIMEOUT 50
20 #define HTTP_READ_TIMEOUT 50
22 #define HTTP_PREFIX "http://"
23 #define HTTP_DEFAULTPORT 80
25 enum message_read_status
{
27 MORE_DATA_EXPECTED
= 0,
29 REQUEST_CANCELED
= -2,
33 enum evhttp_connection_error
{
36 EVCON_HTTP_INVALID_HEADER
,
37 EVCON_HTTP_BUFFER_ERROR
,
38 EVCON_HTTP_REQUEST_CANCEL
43 struct evhttp_request
;
45 /* Indicates an unknown request method. */
46 #define _EVHTTP_REQ_UNKNOWN (1<<15)
48 enum evhttp_connection_state
{
49 EVCON_DISCONNECTED
, /**< not currently connected not trying either*/
50 EVCON_CONNECTING
, /**< tries to currently connect */
51 EVCON_IDLE
, /**< connection is established */
52 EVCON_READING_FIRSTLINE
,/**< reading Request-Line (incoming conn) or
53 **< Status-Line (outgoing conn) */
54 EVCON_READING_HEADERS
, /**< reading request/response headers */
55 EVCON_READING_BODY
, /**< reading request/response body */
56 EVCON_READING_TRAILER
, /**< reading request/response chunked trailer */
57 EVCON_WRITING
/**< writing request/response headers/body */
62 /* A client or server connection. */
63 struct evhttp_connection
{
64 /* we use this tailq only if this connection was created for an http
66 TAILQ_ENTRY(evhttp_connection
) next
;
69 struct bufferevent
*bufev
;
71 struct event retry_ev
; /* for retrying connects */
73 char *bind_address
; /* address to use for binding the src */
74 u_short bind_port
; /* local port for binding the src */
76 char *address
; /* address to connect to */
79 size_t max_headers_size
;
80 ev_uint64_t max_body_size
;
83 #define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */
84 #define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */
85 #define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */
87 int timeout
; /* timeout in seconds for events */
88 int retry_cnt
; /* retry count */
89 int retry_max
; /* maximum number of retries */
91 enum evhttp_connection_state state
;
93 /* for server connections, the http server they are connected with */
94 struct evhttp
*http_server
;
96 TAILQ_HEAD(evcon_requestq
, evhttp_request
) requests
;
98 void (*cb
)(struct evhttp_connection
*, void *);
101 void (*closecb
)(struct evhttp_connection
*, void *);
104 struct deferred_cb read_more_deferred_cb
;
106 struct event_base
*base
;
107 struct evdns_base
*dns_base
;
110 /* A callback for an http server */
112 TAILQ_ENTRY(evhttp_cb
) next
;
116 void (*cb
)(struct evhttp_request
*req
, void *);
120 /* both the http server as well as the rpc system need to queue connections */
121 TAILQ_HEAD(evconq
, evhttp_connection
);
123 /* each bound socket is stored in one of these */
124 struct evhttp_bound_socket
{
125 TAILQ_ENTRY(evhttp_bound_socket
) next
;
127 struct evconnlistener
*listener
;
130 /* server alias list item. */
131 struct evhttp_server_alias
{
132 TAILQ_ENTRY(evhttp_server_alias
) next
;
134 char *alias
; /* the server alias. */
138 /* Next vhost, if this is a vhost. */
139 TAILQ_ENTRY(evhttp
) next_vhost
;
141 /* All listeners for this host */
142 TAILQ_HEAD(boundq
, evhttp_bound_socket
) sockets
;
144 TAILQ_HEAD(httpcbq
, evhttp_cb
) callbacks
;
146 /* All live connections on this host. */
147 struct evconq connections
;
149 TAILQ_HEAD(vhostsq
, evhttp
) virtualhosts
;
151 TAILQ_HEAD(aliasq
, evhttp_server_alias
) aliases
;
153 /* NULL if this server is not a vhost */
158 size_t default_max_headers_size
;
159 ev_uint64_t default_max_body_size
;
161 /* Bitmask of all HTTP methods that we accept and pass to user
163 ev_uint16_t allowed_methods
;
165 /* Fallback callback if all the other callbacks for this connection
167 void (*gencb
)(struct evhttp_request
*req
, void *);
170 struct event_base
*base
;
173 /* XXX most of these functions could be static. */
175 /* resets the connection; can be reused for more requests */
176 void evhttp_connection_reset(struct evhttp_connection
*);
178 /* connects if necessary */
179 int evhttp_connection_connect(struct evhttp_connection
*);
181 /* notifies the current request that it failed; resets connection */
182 void evhttp_connection_fail(struct evhttp_connection
*,
183 enum evhttp_connection_error error
);
185 enum message_read_status
;
187 enum message_read_status
evhttp_parse_firstline(struct evhttp_request
*, struct evbuffer
*);
188 enum message_read_status
evhttp_parse_headers(struct evhttp_request
*, struct evbuffer
*);
190 void evhttp_start_read(struct evhttp_connection
*);
192 /* response sending HTML the data in the buffer */
193 void evhttp_response_code(struct evhttp_request
*, int, const char *);
194 void evhttp_send_page(struct evhttp_request
*, struct evbuffer
*);