Skip to content

Commit 1e30935

Browse files
committed
client: don't advertise keep-alive when sending error replies
Commit 15346de ("client: Always close connection with request body in case of error") added logic to close keep alive connections on HTTP errors due to unconsumed request body data. However, since the check happens after emitting the standard HTTP headers, uhttpd might incorrectly reply with a `Connection: keep-alive` even if it is going to close the connection. Move the check before the emitting of the response headers in order to ensure that we're sending the correct `Connection: close` line. Fixes: 15346de ("client: Always close connection with request body in case of error") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
1 parent d83a891 commit 1e30935

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

client.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,6 @@ uh_client_error(struct client *cl, int code, const char *summary, const char *fm
141141
struct http_request *r = &cl->request;
142142
va_list arg;
143143

144-
uh_http_header(cl, code, summary);
145-
ustream_printf(cl->us, "Content-Type: text/html\r\n\r\n");
146-
147-
uh_chunk_printf(cl, "<h1>%s</h1>", summary);
148-
149-
if (fmt) {
150-
va_start(arg, fmt);
151-
uh_chunk_vprintf(cl, fmt, arg);
152-
va_end(arg);
153-
}
154-
155144
/* Close the connection even when keep alive is set, when it
156145
* contains a request body, as it was not read and we are
157146
* currently out of sync. Without handling this the body will be
@@ -163,6 +152,17 @@ uh_client_error(struct client *cl, int code, const char *summary, const char *fm
163152
cl->request.connection_close = true;
164153
}
165154

155+
uh_http_header(cl, code, summary);
156+
ustream_printf(cl->us, "Content-Type: text/html\r\n\r\n");
157+
158+
uh_chunk_printf(cl, "<h1>%s</h1>", summary);
159+
160+
if (fmt) {
161+
va_start(arg, fmt);
162+
uh_chunk_vprintf(cl, fmt, arg);
163+
va_end(arg);
164+
}
165+
166166
uh_request_done(cl);
167167
}
168168

0 commit comments

Comments
 (0)