nuclear@1: #ifndef HTTP_H_ nuclear@1: #define HTTP_H_ nuclear@1: nuclear@1: enum http_method { nuclear@1: HTTP_UNKNOWN, nuclear@1: HTTP_OPTIONS, nuclear@1: HTTP_GET, nuclear@1: HTTP_HEAD, nuclear@1: HTTP_POST, nuclear@1: HTTP_PUT, nuclear@1: HTTP_DELETE, nuclear@1: HTTP_TRACE, nuclear@1: HTTP_CONNECT, nuclear@1: nuclear@1: NUM_HTTP_METHODS nuclear@1: }; nuclear@1: nuclear@1: struct http_req_header { nuclear@1: enum http_method method; nuclear@1: char *uri; nuclear@1: int ver_major, ver_minor; /* http version */ nuclear@2: char **hdrfields; nuclear@2: int num_hdrfields; nuclear@3: int body_offset; nuclear@1: }; nuclear@1: nuclear@5: struct http_resp_header { nuclear@5: int status; nuclear@5: int ver_major, ver_minor; nuclear@5: char **fields; nuclear@5: int num_fields; nuclear@5: }; nuclear@5: nuclear@3: #define HTTP_HDR_OK 0 nuclear@3: #define HTTP_HDR_INVALID -1 nuclear@3: #define HTTP_HDR_NOMEM -2 nuclear@3: #define HTTP_HDR_PARTIAL -3 nuclear@1: nuclear@2: int http_parse_header(struct http_req_header *hdr, const char *buf, int bufsz); nuclear@3: void http_print_header(struct http_req_header *hdr); nuclear@3: void http_destroy_header(struct http_req_header *hdr); nuclear@2: nuclear@5: int http_init_resp(struct http_resp_header *resp); nuclear@5: int http_add_resp_field(struct http_resp_header *resp, const char *fmt, ...); nuclear@5: void http_destroy_resp(struct http_resp_header *resp); nuclear@5: int http_serialize_resp(struct http_resp_header *resp, char *buf); nuclear@5: nuclear@2: const char *http_strmsg(int code); nuclear@2: nuclear@1: #endif /* HTTP_H_ */