summaryrefslogtreecommitdiff
path: root/source/kit/http1.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/kit/http1.h')
-rw-r--r--source/kit/http1.h35
1 files changed, 25 insertions, 10 deletions
diff --git a/source/kit/http1.h b/source/kit/http1.h
index f4e5fc6..98190ea 100644
--- a/source/kit/http1.h
+++ b/source/kit/http1.h
@@ -16,8 +16,6 @@
extern "C" {
#endif
-#define KIT_HTTP1_CONTENT_TYPE \
- "Content-Type: text/plain; version=0.0.4; charset=utf-8";
#define KIT_HTTP1_NEWLINE "\r\n"
#define KIT_HTTP1_SPACE " "
#define KIT_HTTP1_HEADER_SEPARATOR ": "
@@ -62,6 +60,7 @@ typedef struct {
kit_str_builder_t response;
kit_str_builder_t response_str;
kit_http1_str_map_t header;
+ kit_str_builder_t header_str;
kit_str_builder_t body;
} kit_http1_response_t;
@@ -120,7 +119,7 @@ static kit_str_t kit_http1_tok_next(kit_http1_tok_t *tok,
// - Return error status
static void kit_http1_uri_init(kit_http1_uri_t *uri, kit_str_t input,
kit_allocator_t *alloc) {
- static const char port_80[] = "80";
+ static const kit_str_t port_80 = { .size = 2, .values = "80" };
assert(uri != NULL);
if (uri == NULL)
@@ -155,7 +154,7 @@ static void kit_http1_uri_init(kit_http1_uri_t *uri, kit_str_t input,
// - HTTPS default port 443
uri->port = kit_http1_tok_tail(&host_port_tok);
if (uri->port.size == 0)
- uri->port = SZ(port_80);
+ uri->port = port_80;
uri->address = kit_http1_tok_next(&input_tok, SZ("?"), 1);
uri->query_string = kit_http1_tok_next(&input_tok, SZ("#"), 1);
@@ -193,7 +192,13 @@ static void kit_http1_uri_init(kit_http1_uri_t *uri, kit_str_t input,
}
static void kit_http1_uri_destroy(kit_http1_uri_t *uri) {
- // TODO
+ assert(uri != NULL);
+ if (uri == NULL)
+ return;
+
+ KIT_DA_DESTROY(uri->parameters);
+
+ memset(uri, 0, sizeof *uri);
}
static kit_str_t kit_http1_method_to_str(i32 method) {
@@ -436,7 +441,7 @@ static kit_http1_response_t kit_http1_request(
res.response_str = kit_str_build(
kit_http1_tok_next(&buf_tok, SZ(KIT_HTTP1_NEWLINE), 0), alloc);
- kit_str_builder_t header = kit_str_build(
+ res.header_str = kit_str_build(
kit_http1_tok_next(&buf_tok,
SZ(KIT_HTTP1_NEWLINE KIT_HTTP1_NEWLINE), 0),
alloc);
@@ -444,8 +449,8 @@ static kit_http1_response_t kit_http1_request(
res.body = kit_str_build(kit_http1_tok_tail(&buf_tok), alloc);
kit_http1_tok_t header_tok = {
- .str = (kit_str_t) { .size = header.size,
- .values = header.values },
+ .str = (kit_str_t) { .size = res.header_str.size,
+ .values = res.header_str.values },
.position = 0
};
@@ -481,8 +486,18 @@ static kit_http1_response_t kit_http1_request(
static void kit_http1_response_destroy(
kit_http1_response_t *response) {
- // TODO
- //
+ assert(response != NULL);
+ if (response == NULL)
+ return;
+
+ KIT_DA_DESTROY(response->protocol);
+ KIT_DA_DESTROY(response->response);
+ KIT_DA_DESTROY(response->response_str);
+ KIT_DA_DESTROY(response->header);
+ KIT_DA_DESTROY(response->header_str);
+ KIT_DA_DESTROY(response->body);
+
+ memset(response, 0, sizeof *response);
}
#ifdef __GNUC__