aboutsummaryrefslogtreecommitdiff
path: root/libnet/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnet/http.c')
-rw-r--r--libnet/http.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/libnet/http.c b/libnet/http.c
new file mode 100644
index 0000000..b1febbc
--- /dev/null
+++ b/libnet/http.c
@@ -0,0 +1,43 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#include <def.h>
+#include <mem.h>
+#include <print.h>
+#include <str.h>
+
+char *http_data(char *r)
+{
+ char *h = NULL;
+ for (u32 i = 0; i < strlen(r); ++i) {
+ if (r[i] == '\r' && r[i + 1] == '\n' && r[i + 2] == '\r' && r[i + 3] == '\n') {
+ h = &r[i + 4];
+ break;
+ }
+ }
+ return h;
+}
+
+char *http_code(char *r)
+{
+ char *code = malloc(4);
+ char tmp = r[12];
+ r[12] = '\0';
+ memcpy(code, r + 9, 3);
+ code[3] = '\0';
+ r[12] = tmp;
+ return code;
+}
+
+char *http_query_get(const char *url, const char *path)
+{
+ char *query = malloc(27 + strlen(url)); // TODO: Dynamic http length etc
+ query[0] = '\0';
+ strcat(query, "GET ");
+ if (path[0] != '/')
+ strcat(query, "/");
+ strcat(query, path);
+ strcat(query, " HTTP/1.1\r\nHost: ");
+ strcat(query, url);
+ strcat(query, "\r\n\r\n");
+ return query;
+}