From: Eric Wong <e@80x24.org>
To: mwrap-perl@80x24.org
Subject: [PATCH 2/3] httpd: drop persistent connection support
Date: Wed, 21 Dec 2022 11:34:04 +0000 [thread overview]
Message-ID: <20221221113405.2129-3-e@80x24.org> (raw)
In-Reply-To: <20221221113405.2129-1-e@80x24.org>
It's not worth the extra complexity, binary size, and icache
bloat for a AF_UNIX-only server.
---
httpd.h | 33 +++++++--------------------------
1 file changed, 7 insertions(+), 26 deletions(-)
diff --git a/httpd.h b/httpd.h
index a59c9dd..128836c 100644
--- a/httpd.h
+++ b/httpd.h
@@ -78,9 +78,8 @@ struct mw_h1 { /* each HTTP/1.x client (heap) */
int fd;
short events; /* for poll */
unsigned prev_len:13; /* capped by MW_RBUF_SIZE */
- unsigned persist:1; /* HTTP/1.1 */
unsigned has_input:1;
- unsigned unused_:1;
+ unsigned unused_:2;
struct mw_h1req *h1r; /* only for slow clients */
unsigned long in_len;
struct mw_wbuf *wbuf;
@@ -211,9 +210,7 @@ static enum mw_qev h1_send_flush(struct mw_h1 *h1)
}
}
} while (mh.msg_iovlen);
- free(wbuf);
- h1->wbuf = NULL;
- return h1->persist ? MW_QEV_RD : h1_close(h1);
+ return h1_close(h1);
}
static FILE *fbuf_init(struct mw_fbuf *fb)
@@ -285,6 +282,7 @@ static enum mw_qev h1_200(struct mw_h1 *h1, struct mw_fbuf *fb, const char *ct)
clen -= sizeof(struct mw_wbuf);
mwrap_assert(clen >= 0);
FPUTS("HTTP/1.1 200 OK\r\n"
+ "Connection: close\r\n"
"Expires: Fri, 01 Jan 1980 00:00:00 GMT\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache, max-age=0, must-revalidate\r\n"
@@ -309,8 +307,8 @@ static enum mw_qev h1_404(struct mw_h1 *h1)
{
static const char r404[] = "HTTP/1.1 404 Not Found\r\n"
"Content-Type: text/html\r\n"
+ "Connection: close\r\n"
"Content-Length: 10\r\n\r\n" "Not Found\n";
- if (h1->has_input) h1->persist = 0;
return h1_res_oneshot(h1, r404, sizeof(r404) - 1);
}
@@ -319,16 +317,12 @@ static int name_eq(const struct phr_header *h, const char *name, size_t len)
{
return h->name_len == len && !strncasecmp(name, h->name, len);
}
-#define VAL_EQ(h, VAL) val_eq(h, VAL, sizeof(VAL)-1)
-static int val_eq(const struct phr_header *h, const char *val, size_t len)
-{
- return h->value_len == len && !strncasecmp(val, h->value, len);
-}
static enum mw_qev h1_do_reset(struct mw_h1 *h1)
{
static const char r200[] = "HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
+ "Connection: close\r\n"
"Content-Length: 6\r\n\r\n" "reset\n";
mwrap_reset();
return h1_res_oneshot(h1, r200, sizeof(r200) - 1);
@@ -338,6 +332,7 @@ static enum mw_qev h1_do_trim(struct mw_h1 *h1)
{
static const char r200[] = "HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
+ "Connection: close\r\n"
"Content-Length: 9\r\n\r\n" "trimming\n";
malloc_trim(0);
return h1_res_oneshot(h1, r200, sizeof(r200) - 1);
@@ -867,15 +862,13 @@ static void ctl_set(struct mw_h1 *h1, long n)
static enum mw_qev h1_parse_harder(struct mw_h1 *h1, struct mw_h1req *h1r)
{
- enum { HDR_IGN, HDR_CONN, HDR_XENC, HDR_CLEN } cur = HDR_IGN;
- bool conn_set = false;
+ enum { HDR_IGN, HDR_XENC, HDR_CLEN } cur = HDR_IGN;
char *end;
struct phr_header *hdr = h1r->hdr;
long depth = -1;
h1->prev_len = 0;
h1->has_input = 0;
- h1->persist = h1r->minor_ver >= 1 ? 1 : 0;
h1->in_len = 0;
for (hdr = h1r->hdr; h1r->nr_hdr--; hdr++) {
@@ -883,8 +876,6 @@ static enum mw_qev h1_parse_harder(struct mw_h1 *h1, struct mw_h1req *h1r)
cur = HDR_XENC;
else if (NAME_EQ(hdr, "Content-Length"))
cur = HDR_CLEN;
- else if (NAME_EQ(hdr, "Connection"))
- cur = HDR_CONN;
else if (NAME_EQ(hdr, "Trailer"))
return h1_400(h1);
else if (hdr->name) {
@@ -906,16 +897,6 @@ static enum mw_qev h1_parse_harder(struct mw_h1 *h1, struct mw_h1req *h1r)
if (!hdr->value_len)
continue;
switch (cur) {
- case HDR_CONN:
- if (conn_set) return h1_400(h1);
- conn_set = true;
- if (VAL_EQ(hdr, "close"))
- h1->persist = 0;
- else if (VAL_EQ(hdr, "keep-alive"))
- h1->persist = 1;
- else
- return h1_400(h1);
- break;
case HDR_XENC:
return h1_400(h1);
case HDR_CLEN:
next prev parent reply other threads:[~2022-12-21 11:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-21 11:34 [PATCH 0/3] httpd: debloating and refining Eric Wong
2022-12-21 11:34 ` [PATCH 1/3] httpd: drop connection if 404 on POST bodies Eric Wong
2022-12-21 11:34 ` Eric Wong [this message]
2022-12-21 11:34 ` [PATCH 3/3] httpd: do not waste TSD space Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221221113405.2129-3-e@80x24.org \
--to=e@80x24.org \
--cc=mwrap-perl@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap-perl.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).