aboutsummaryrefslogtreecommitdiff
path: root/src/molerat/request.c
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2024-07-23 17:48:28 -0400
committerShav Kinderlehrer <[email protected]>2024-07-23 17:48:28 -0400
commitdc0f2ce9ba97ebb47e05b80a511da6eb29818b63 (patch)
treedc83035069f5a015047be1ca3da6f65781eb4695 /src/molerat/request.c
parentf638f4bd1e3a03bc2bdd5f9dcd57d4830fd3c553 (diff)
downloadmolehole-dc0f2ce9ba97ebb47e05b80a511da6eb29818b63.tar.gz
molehole-dc0f2ce9ba97ebb47e05b80a511da6eb29818b63.zip
Merge old-moleholencurses
Diffstat (limited to 'src/molerat/request.c')
-rwxr-xr-xsrc/molerat/request.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/molerat/request.c b/src/molerat/request.c
new file mode 100755
index 0000000..1d59a09
--- /dev/null
+++ b/src/molerat/request.c
@@ -0,0 +1,34 @@
+#include <ncurses.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "request.h"
+#include "url.h"
+
+char *get_request_kind(enum RequestKind kind) {
+ switch (kind) {
+ case GET:
+ return "get";
+ case PUT:
+ return "put";
+ case DEL:
+ return "del";
+ }
+}
+
+char *request_to_string(struct request *req) {
+ int len = sizeof(struct request) +
+ 6; // +1 for null terminator +5 for request whitespace
+
+ char *buf = malloc(len);
+
+ char *kind = get_request_kind(req->kind);
+ char *host = req->url.host != NULL ? req->url.host : "";
+ char *path = req->url.path != NULL ? req->url.path : "";
+ char *query = req->url.query != NULL ? req->url.query : "";
+ char *fragment = req->url.fragment != NULL ? req->url.fragment : "";
+
+ snprintf(buf, len, "%s %s%s%s%s\r\n\r\n", kind, host, path, query, fragment);
+
+ return buf;
+}