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.
This commit is contained in:
parent
dc063b90cb
commit
30a101717c
|
@ -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.
|
||||
|
||||
|
|
38
http.c
38
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue