From 30a101717c8ac825f6ce676c6d717964f19307a8 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Fri, 28 Apr 2023 00:30:44 +0200 Subject: [PATCH] Remove HTTP/1.0 support Considering http.h defined HTTP/1.1-only responses such as "303 See Other", as well as incoming HTTP/1.1-only features (e.g.: byte serving), it did not make much sense to keep a somewhat broken compatibility against HTTP/1.0. Unfortunately, this breaks support with some existing clients such as lynx(1), even if HTTP/1.0 was already deprecated many years ago. However, even lynx(1) can be configured to support HTTP/1.1. --- README.md | 2 +- http.c | 38 +++++--------------------------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 9f37f75..1c62dba 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ simplicity and efficiency. - Private access directory with file uploading, with configurable quota. - Read-only public file sharing. -- Its own, tiny HTTP/1.0 and 1.1-compatible server. +- Its own, tiny HTTP/1.1-compatible server. - A simple JSON file as the credentials database. - No JavaScript. diff --git a/http.c b/http.c index 8ad568e..5308fa5 100644 --- a/http.c +++ b/http.c @@ -15,6 +15,8 @@ #include #include +#define HTTP_VERSION "HTTP/1.1" + struct http_ctx { struct ctx @@ -98,12 +100,6 @@ struct http_ctx struct dynstr d; } wctx; - enum version - { - HTTP_1_0, - HTTP_1_1 - } version; - /* From RFC9112, section 3 (Request line): * It is RECOMMENDED that all HTTP senders and recipients support, * at a minimum, request-line lengths of 8000 octets. */ @@ -111,24 +107,6 @@ struct http_ctx struct http_cfg cfg; }; -static const char *const versions[] = -{ - [HTTP_1_0] = "HTTP/1.0", - [HTTP_1_1] = "HTTP/1.1" -}; - -static int get_version(struct http_ctx *const h, const char *const v) -{ - for (enum version i = 0; i < sizeof versions / sizeof *versions; i++) - if (!strcmp(versions[i], v)) - { - h->version = i; - return 0; - } - - return -1; -} - static void arg_free(struct http_arg *const a) { if (a) @@ -408,7 +386,7 @@ static int start_line(struct http_ctx *const h) int ret = 1, error; char *enc_res = NULL; - if (get_version(h, protocol)) + if (strcmp(protocol, HTTP_VERSION)) { fprintf(stderr, "%s: unsupported protocol %s\n", __func__, protocol); goto end; @@ -630,9 +608,6 @@ static int write_body_mem(struct http_ctx *const h, bool *const close) { const bool close_pending = w->close; - if (h->version == HTTP_1_0) - *close = true; - if ((res = write_ctx_free(w))) fprintf(stderr, "%s: write_ctx_free failed\n", __func__); else if (close_pending) @@ -667,9 +642,6 @@ static int write_body_file(struct http_ctx *const h, bool *const close) { const bool close_pending = w->close; - if (h->version == HTTP_1_0) - *close = true; - if ((res = write_ctx_free(w))) fprintf(stderr, "%s: write_ctx_free failed\n", __func__); else if (close_pending) @@ -763,8 +735,8 @@ static int start_response(struct http_ctx *const h) w->pending = true; dynstr_init(&w->d); - dynstr_append_or_ret_nonzero(&w->d, "%s %d %s\r\n", - versions[h->version], c->code, c->descr); + dynstr_append_or_ret_nonzero(&w->d, HTTP_VERSION " %d %s\r\n", + c->code, c->descr); return 0; }