#pragma once #include #include /* Copy from http_parser.h */ #define HTTP_METHOD_MAP(XX) \ XX(0, DELETE, DELETE) \ XX(1, GET, GET) \ XX(2, HEAD, HEAD) \ XX(3, POST, POST) \ XX(4, PUT, PUT) \ /* pathological */ \ XX(5, CONNECT, CONNECT) \ XX(6, OPTIONS, OPTIONS) \ XX(7, TRACE, TRACE) \ /* WebDAV */ \ XX(8, COPY, COPY) \ XX(9, LOCK, LOCK) \ XX(10, MKCOL, MKCOL) \ XX(11, MOVE, MOVE) \ XX(12, PROPFIND, PROPFIND) \ XX(13, PROPPATCH, PROPPATCH) \ XX(14, SEARCH, SEARCH) \ XX(15, UNLOCK, UNLOCK) \ XX(16, BIND, BIND) \ XX(17, REBIND, REBIND) \ XX(18, UNBIND, UNBIND) \ XX(19, ACL, ACL) \ /* subversion */ \ XX(20, REPORT, REPORT) \ XX(21, MKACTIVITY, MKACTIVITY) \ XX(22, CHECKOUT, CHECKOUT) \ XX(23, MERGE, MERGE) \ /* upnp */ \ XX(24, MSEARCH, M-SEARCH) \ XX(25, NOTIFY, NOTIFY) \ XX(26, SUBSCRIBE, SUBSCRIBE) \ XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \ /* RFC-5789 */ \ XX(28, PATCH, PATCH) \ XX(29, PURGE, PURGE) \ /* CalDAV */ \ XX(30, MKCALENDAR, MKCALENDAR) \ /* RFC-2068, section 19.6.1.2 */ \ XX(31, LINK, LINK) \ XX(32, UNLINK, UNLINK) \ /* icecast */ \ XX(33, SOURCE, SOURCE) \ enum tfe_http_std_method { #define XX(num, name, string) TFE_HTTP_##name = num, HTTP_METHOD_MAP(XX) #undef XX }; enum tfe_http_std_field { TFE_HTTP_UNKNOWN_FIELD = 0, TFE_HTTP_HOST, TFE_HTTP_REFERER, TFE_HTTP_USER_AGENT, TFE_HTTP_COOKIE, TFE_HTTP_PROXY_AUTHORIZATION, TFE_HTTP_AUTHORIZATION, TFE_HTTP_LOCATION, TFE_HTTP_SERVER, TFE_HTTP_ETAG, TFE_HTTP_DATE, TFE_HTTP_TRAILER, TFE_HTTP_TRANSFER_ENCODING, TFE_HTTP_VIA, TFE_HTTP_PRAGMA, TFE_HTTP_CONNECTION, TFE_HTTP_CONT_ENCODING, TFE_HTTP_CONT_LANGUAGE, TFE_HTTP_CONT_LOCATION, TFE_HTTP_CONT_RANGE, TFE_HTTP_CONT_LENGTH, TFE_HTTP_CONT_TYPE, TFE_HTTP_CONT_DISPOSITION, TFE_HTTP_EXPIRES, TFE_HTTP_ACCEPT_ENCODING, }; struct tfe_http_req_spec { int method; char * uri; char * host; char * url; //uri+host char * accept_encoding; }; struct tfe_http_resp_spec { int resp_code; char * content_encoding; }; enum tfe_http_direction { TFE_HTTP_REQUEST = 1, TFE_HTTP_RESPONSE = 2 }; struct tfe_http_half { enum tfe_http_direction direction; short major_version; //HTTP/1.x or HTTP/ 2 short minor_version; //HTTP 1.1 or 1.0 union { struct tfe_http_req_spec req_spec; struct tfe_http_resp_spec resp_spec; }; unsigned int field_cnt; uint64_t cont_len; uint64_t cont_range_from; uint64_t cont_range_to; struct evbuffer * body; }; struct tfe_http_session { int session_id;//? int major_version;//1:HTTP 1.x, 2:HTTP 2 struct tfe_http_half * req; struct tfe_http_half * resp;//value is NULL before response received. }; struct http_field_name { enum tfe_http_std_field field_id; char * field_name; //Non-NULL when field_id isHTTP_UNKNOWN_FIELD. }; const char * tfe_http_field_read(const struct tfe_http_half * half, const struct http_field_name * name); int tfe_http_field_to_range(const char * field_value, long * range_from, long * range_to); int tfe_http_field_to_digit(const char * field_value, long * digit); //******obsolete //long tfe_http_read_num_field(const struct tfe_http_half* half, const struct http_field_name* name); //@Input param interator: NULL to get the first field. //@Output param name: //@return: field value. const char * tfe_http_field_iterate(const struct tfe_http_half * half, void * interator, struct http_field_name * name); struct tfe_http_half * tfe_http_allow_write(const struct tfe_http_half * half); //@param value: NULL for delete //@param name: Could be CHUNK/ENCODING int tfe_http_field_write(struct tfe_http_half * half, const struct http_field_name * name, const char * value); //******obsolete //int tfe_http_field_read_func(const struct tfe_http_half* half, const char* name, char* value, size_t size); enum http_ev_bit_number { REQ_HDR_BITNUM = 0, REQ_BODY_BEGIN_BITNUM, REQ_BODY_CONT_BITNUM, REQ_BODY_END_BITNUM, RESP_HDR_BITNUM, RESP_BODY_BEGIN_BITNUM, RESP_BODY_CONT_BITNUM, RESP_BODY_END_BITNUM }; #define EV_HTTP_REQ_HDR ((uint64_t)1<