12 HTTP_STATE_CONNECTING
,
13 HTTP_STATE_READ_FIRSTLINE
,
14 HTTP_STATE_READ_HEADERS
,
17 HTTP_STATE_TUNNEL_CONNECTING
,
18 HTTP_STATE_TUNNEL_OPEN
,
19 HTTP_STATE_TUNNEL_FLUSHING
40 enum http_conn_error
{
43 ERROR_IDLE_CONN_TIMEDOUT
,
44 ERROR_CLIENT_EXPECTATION_FAILED
,
45 ERROR_CLIENT_POST_WITHOUT_LENGTH
,
46 ERROR_INCOMPLETE_HEADERS
,
47 ERROR_INCOMPLETE_BODY
,
48 ERROR_HEADER_PARSE_FAILED
,
49 ERROR_CHUNK_PARSE_FAILED
,
51 ERROR_TUNNEL_CONNECT_FAILED
,
55 #define HTTP_ERROR_RESPONSE(c) (c >= 400 && c <= 599)
65 TAILQ_ENTRY(http_request
) next
;
66 enum http_method meth
;
68 enum http_version vers
;
69 struct header_list
*headers
;
71 TAILQ_HEAD(http_request_list
, http_request
);
73 struct http_response
{
74 enum http_version vers
;
77 struct header_list
*headers
;
81 void (*on_connect
)(struct http_conn
*, void *);
82 void (*on_error
)(struct http_conn
*, enum http_conn_error
, void *);
83 void (*on_client_request
)(struct http_conn
*, struct http_request
*, void *);
84 void (*on_server_continuation
)(struct http_conn
*, void *);
85 void (*on_server_response
)(struct http_conn
*, struct http_response
*, void *);
86 void (*on_read_body
)(struct http_conn
*, struct evbuffer
*, void *);
87 void (*on_msg_complete
)(struct http_conn
*, void *);
89 /* called when it is ok to write more data after choaking */
90 void (*on_write_more
)(struct http_conn
*, void *);
92 void (*on_flush
)(struct http_conn
*, void *);
95 struct http_conn
*http_conn_new(struct event_base
*base
, evutil_socket_t sock
,
96 enum http_type type
, const struct http_cbs
*cbs
,
99 int http_conn_connect(struct http_conn
*conn
, struct evdns_base
*dns
,
100 int family
, const char *host
, int port
);
102 void http_conn_free(struct http_conn
*conn
);
104 void http_conn_write_request(struct http_conn
*conn
, struct http_request
*req
);
105 int http_conn_expect_continue(struct http_conn
*conn
);
106 void http_conn_write_continue(struct http_conn
*conn
);
107 void http_conn_write_response(struct http_conn
*conn
, struct http_response
*resp
);
109 /* return: 0 on choaked, 1 on queued. */
110 int http_conn_write_buf(struct http_conn
*conn
, struct evbuffer
*buf
);
111 void http_conn_write_finished(struct http_conn
*conn
);
113 int http_conn_current_message_has_body(struct http_conn
*conn
);
114 void http_conn_set_current_message_bodyless(struct http_conn
*conn
);
116 enum http_te
http_conn_get_current_message_body_encoding(struct http_conn
*conn
);
117 ev_int64_t
http_conn_get_current_message_body_length(struct http_conn
*conn
);
118 void http_conn_set_output_encoding(struct http_conn
*conn
, enum http_te te
);
119 int http_conn_is_persistent(struct http_conn
*conn
);
120 void http_conn_disable_persistence(struct http_conn
*conn
);
122 /* turn read off/on; useful for when the other end is choking */
123 void http_conn_stop_reading(struct http_conn
*conn
);
124 void http_conn_start_reading(struct http_conn
*conn
);
126 void http_conn_flush(struct http_conn
*conn
);
128 void http_conn_send_error(struct http_conn
*conn
, int code
,
129 const char *fmt
, ...);
131 int http_conn_start_tunnel(struct http_conn
*conn
, struct evdns_base
*dns
,
132 int family
, const char *host
, int port
);
134 const char *http_conn_error_to_string(enum http_conn_error err
);
135 const char *http_method_to_string(enum http_method m
);
136 const char *http_version_to_string(enum http_version v
);
138 void http_request_free(struct http_request
*req
);
139 void http_response_free(struct http_response
*req
);