vessel/web/include/http.h
Arija A. e7f57f8526
impl: Tempfiles and ByteStreams
Signed-off-by: Arija A. <ari@ari.lt>
2025-06-14 20:57:28 +03:00

75 lines
3.4 KiB
C

#ifndef VESSEL_WEB_HTTP_H_
#define VESSEL_WEB_HTTP_H_
#include "conf.h"
#include <vessel/def.h>
#include <vessel/hmap.h>
#define VW_HTTP_OLDEST_SUPPORTED "HTTP/1.0"
#define VW_HTTP_NEWEST_SUPPORTED "HTTP/1.1"
#define VW_HTTP_METHOD_MAX_LENGTH 32
#define VW_HTTP_MESSAGE_MAX_LENGTH 64
#define VW_HTTP_BUFFER_MAX_SIZE 65536
#define VW_HTTP_PATH_MAX_LENGTH 4096
#define VW_HTTP_HEADER_KEY_MAX_LENGTH 4096
#define VW_HTTP_HEADER_VALUE_MAX_LENGTH 16384
#define VW_HTTP_VERSION_LENGTH 8
#define VW_HTTP_CRLF "\r\n"
#define VW_HTTP_CRLF_LENGTH 2
#define VW_HTTP_2_CRLF "\r\n\r\n"
#define VW_HTTP_2_CRLF_LENGTH 4
/*
* Common headers which have case-insensitive values.
* TODO: Convert to enum?
*/
#define VW_HTTP_ACCEPT_HASH 14238959134108615210ULL /* accept */
#define VW_HTTP_USER_AGENT_HASH 13373452787310402909ULL /* user-agent */
#define VW_HTTP_CACHE_CONTROL_HASH 8298606282462953570ULL /* cache-control */
#define VW_HTTP_ACCEPT_ENCODING_HASH \
15961257851207993634ULL /* accept-encoding \
*/
#define VW_HTTP_ACCEPT_LANGUAGE_HASH 5812279770095983820ULL /* accept-language */
#define VW_HTTP_ORIGIN_HASH 10750792531167945166ULL /* origin */
#define VW_HTTP_HOST_HASH 14338446849766634905ULL /* host */
#define VW_HTTP_ACCESS_CONTROL_REQUEST_METHOD_HASH \
16129132534263958600ULL /* access-control-request-method */
#define VW_HTTP_ACCESS_CONTROL_REQUEST_HEADERS_HASH \
7836744697163470975ULL /* access-control-request-headers */
#define VW_HTTP_X_REQUESTED_WITH_HASH \
463209645848283224ULL /* x-requested-with \
*/
#define VW_HTTP_CONNECTION_HASH 5074835897224029590ULL /* connection */
#define VW_HTTP_ACCEPT_RANGES_HASH 3128858506385276680ULL /* accept-ranges */
#define VW_HTTP_RANGE_HASH 16389903484269220805ULL /* range */
#define VW_HTTP_CONTENT_ENCODING_HASH \
3937762082958960741ULL /* content-encoding \
*/
#define VW_HTTP_EXPECT_HASH 2398226705292924901ULL /* expect */
#define VW_HTTP_TE_HASH 1709019631650117594ULL /* te */
/* The most minimal request could look like `GET / HTTP/1.1\r\n\r\n` which
* is 18 bytes. */
#define VW_HTTP_SMALLEST_REQUEST 18
#define VW_HTTP_TIME_SIZE 64
typedef char vw_HTTPTime[VW_HTTP_TIME_SIZE];
const char *vw_HTTP_code_to_message(uint16_t code) __attribute__((pure));
const char *vw_HTTP_code_to_description(uint16_t code) __attribute__((pure));
const char *vw_HTTP_code_to_colour(uint16_t code) __attribute__((pure));
ssize_t vw_HTTP_url_decode(char *str);
char *vw_HTTP_html_encode(const char *str);
ssize_t vw_HTTP_html_decode(char *str);
bool vw_HTTP_parse_query(const char *param_start, vs_HMap *out);
bool vw_HTTP_validate_request_headers(const void *request, size_t size);
size_t vw_HTTP_time(time_t ts, vw_HTTPTime out);
bool vw_HTTP_parse_multipart_header(const char *value, vs_HMap *out);
bool vw_HTTP_parse_headers(const void *data, size_t buf_size, vs_HMap *out, size_t *idx);
#endif /* VESSEL_WEB_HTTP_H_ */