response.h (1219B)
1 2 #ifndef RESPONSE_H 3 #define RESPONSE_H 4 5 #include <stddef.h> 6 #include <stdbool.h> 7 8 #define INNER_STRINGIZE(s) #s 9 #define STRINGIZE(s) INNER_STRINGIZE(s) 10 11 enum StatusCode { 12 Continue = 100, 13 SwitchingProtocols = 101, 14 OK = 200, 15 Created = 201, 16 Accepted = 202, 17 NonAuthoritativeInformation = 203, 18 NoContent = 204, 19 ResetContent = 205, 20 PartialContent = 206, 21 MultipleChoices = 300, 22 MovedPermanently = 301, 23 Found = 302, 24 SeeOther = 303, 25 NotModified = 304, 26 UseProxy = 305, 27 TemporaryRedirect = 307, 28 BadRequest = 400, 29 Unauthorized = 401, 30 PaymentRequired = 402, 31 Forbidden = 403, 32 NotFound = 404, 33 MethodNotAllowed = 405, 34 NotAcceptable = 406, 35 InternalServerError = 500, 36 NotImplemented = 501, 37 }; 38 39 typedef struct response { 40 char header[512]; 41 char* content; 42 size_t sz; 43 } response_t; 44 45 const char* ext_to_mtype(char* ext); 46 47 response_t __resp_new(enum StatusCode code, char* code_name); 48 #define resp_new(code) __resp_new(code, STRINGIZE(code)) 49 50 void resp_add_hdr(response_t* r, char* hdr, char* val); 51 void resp_add_content(response_t* r, char* content, size_t content_len); 52 void resp_set_ctype(response_t* r, char* ext); 53 54 #endif