aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-04-28 00:30:44 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-07-20 23:52:53 +0200
commit30c76e6d18a99654946e91509714b7ac531aa0ec (patch)
treede92a4f3218c941a81b36a99c83ee52c9f14c8d9
parent2e8485d687dd5f673b8d2aadb0816571d3f32cb7 (diff)
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.
-rw-r--r--http.c38
1 files changed, 5 insertions, 33 deletions
diff --git a/http.c b/http.c
index 8ad568e..5308fa5 100644
--- a/http.c
+++ b/http.c
@@ -15,6 +15,8 @@
#include <strings.h>
#include <time.h>
+#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;
}