diff options
| author | Soikk | 2025-06-14 02:48:33 +0200 |
|---|---|---|
| committer | Soikk | 2025-06-14 02:48:33 +0200 |
| commit | 02d02ed4ddba4d66d3f1d5ec92bfe9ec4ca182d0 (patch) | |
| tree | 9ac6a83eb11455314946af54f1d3740f015c99c9 /src/net | |
| parent | 4b87e75761cc90d6fe57dff08f8adc5559999508 (diff) | |
| download | soikk-server-02d02ed4ddba4d66d3f1d5ec92bfe9ec4ca182d0.tar.xz soikk-server-02d02ed4ddba4d66d3f1d5ec92bfe9ec4ca182d0.tar.zst | |
Reworked config. Added mime module. Reworked mime related functions in net module.
Diffstat (limited to 'src/net')
| -rwxr-xr-x | src/net/net.c | 55 | ||||
| -rwxr-xr-x | src/net/net.h | 11 |
2 files changed, 5 insertions, 61 deletions
diff --git a/src/net/net.c b/src/net/net.c index e7c5981..3e70cef 100755 --- a/src/net/net.c +++ b/src/net/net.c @@ -12,47 +12,6 @@ str response_headers[] = { sstr("Transfer-Encoding"), }; -struct { - str fmt; - str type; -} mime_types[] = { - {.fmt = sstr("avif"), .type = sstr("image/avif")}, - {.fmt = sstr("bmp"), .type = sstr("image/bmp")}, - {.fmt = sstr("css"), .type = sstr("text/css")}, - {.fmt = sstr("csv"), .type = sstr("text/csv")}, - {.fmt = sstr("eot"), .type = sstr("application/vnd.ms-fontobject")}, - {.fmt = sstr("gz"), .type = sstr("application/gzip")}, - {.fmt = sstr("gif"), .type = sstr("image/gif")}, - {.fmt = sstr("html"), .type = sstr("text/html")}, - {.fmt = sstr("ico"), .type = sstr("image/vnd.microsoft.icon")}, - {.fmt = sstr("jpg"), .type = sstr("image/jpeg")}, - {.fmt = sstr("jpeg"), .type = sstr("image/jpeg")}, - {.fmt = sstr("js"), .type = sstr("text/javascript")}, - {.fmt = sstr("json"), .type = sstr("application/json")}, - {.fmt = sstr("midi"), .type = sstr("audio/midi")}, - {.fmt = sstr("mp3"), .type = sstr("audio/mpeg")}, - {.fmt = sstr("mp4"), .type = sstr("video/mp4")}, - {.fmt = sstr("mpeg"), .type = sstr("video/mpeg")}, - {.fmt = sstr("png"), .type = sstr("image/png")}, - {.fmt = sstr("pdf"), .type = sstr("application/pdf")}, - {.fmt = sstr("php"), .type = sstr("application/x-httpd-php")}, - {.fmt = sstr("rar"), .type = sstr("application/vnd.rar")}, - {.fmt = sstr("svg"), .type = sstr("image/svg+xml")}, - {.fmt = sstr("tiff"), .type = sstr("image/tiff")}, - {.fmt = sstr("ts"), .type = sstr("video/mp2t")}, - {.fmt = sstr("ttf"), .type = sstr("font/ttf")}, - {.fmt = sstr("txt"), .type = sstr("text/plain")}, - {.fmt = sstr("wav"), .type = sstr("audio/wav")}, - {.fmt = sstr("weba"), .type = sstr("audio/webm")}, - {.fmt = sstr("webm"), .type = sstr("video/webm")}, - {.fmt = sstr("webp"), .type = sstr("image/webp")}, - {.fmt = sstr("woff"), .type = sstr("font/woff")}, - {.fmt = sstr("woff2"), .type = sstr("font/woff2")}, - {.fmt = sstr("xml"), .type = sstr("application/xml")}, - {.fmt = sstr("zip"), .type = sstr("application/zip")}, - {.fmt = sstr("7z"), .type = sstr("application/x-7z-compressed")}, -}; - LIST(struct uri_mod) uri_rewrites = NULL; static int pleasesslgivemetheerror(int ssl_get_error){ @@ -597,20 +556,14 @@ void send_file(http_worker *hw, str filename){ } log_info("sending '%.*s'", filename.len, filename.ptr); - enum mime_type type = TXT; - str fmt = dstr(get_extension(filename.ptr)); - for(int i = 0; i < sizeof(mime_types)/sizeof(mime_types[0]); i++){ - if(strncmp(fmt.ptr, mime_types[i].fmt.ptr, fmt.len) == 0){ - type = i; - break; - } - } - free_str(&fmt); + str ext = dsstr(get_extension(filename.ptr)); + str type = get_mime_type(ext); + if(type.len == 0) type = sstr("text/plain"); struct http_message hm = { .resp_ver = sstr("HTTP/1.1"), .status = sstr("200"), .reason = sstr("OK"), .hlen = 2, .headers = { - { .name = response_headers[CONTENT_TYPE], .value = mime_types[type].type }, + { .name = response_headers[CONTENT_TYPE], .value = type }, { .name = response_headers[CONTENT_LENGTH], .value = utostr(fsize, 10) } }, .body = {0}, diff --git a/src/net/net.h b/src/net/net.h index 79886df..dc7c147 100755 --- a/src/net/net.h +++ b/src/net/net.h @@ -19,6 +19,7 @@ #include "list/list.h" #include "files/files.h" #include "log/log.h" +#include "mime/mime.h" #include <openssl/ssl.h> #include <openssl/err.h> #include <poll.h> @@ -34,16 +35,6 @@ typedef enum http_method { } http_method; - -enum mime_type { - AVIF, BMP, CSS, CSV, GZ, GIF, HTML, - ICO, JPG, JPEG, JS, JSON, MIDI, MP3, - MP4, MPEG, PNG, PDF, PHP, RAR, TIFF, TS, - TXT, WAV, WEBA, WEBM, WEBP, XML, ZIP, - _7Z, -}; - - struct uri { str path; str query; |
