Skip to content
Snippets Groups Projects
Commit 83c0999b authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix issue #942

Session is initialized to HTTP/0.9 (which doesn't send headers) and
the HEAD method (which doesn't send a body). This was caught in
writebuf(), which returned 0 due to the body not being sent, which
caused the error to be logged.

Set the values to HTTP/1.0 and GET so we can call send_error()
before we read a request line and actually send an error.

Additionally, add a LOG_INFO to writebuf() when it returns 0 due
to body being disabled to make this kind of thing easier to find
in the future.

Finally, don't attempt to send an error body if send_headers()
fails or if we should not send a body.

This would also allow us to send a 408 if we wanted to, but I've
never been convinced that's useful.
parent 2588c5cf
No related branches found
No related tags found
No related merge requests found
Pipeline #9028 passed
...@@ -606,8 +606,10 @@ static int writebuf(http_session_t *session, const char *buf, size_t len) ...@@ -606,8 +606,10 @@ static int writebuf(http_session_t *session, const char *buf, size_t len)
size_t sent = 0; size_t sent = 0;
size_t avail; size_t avail;
if (session->req.sent_headers && session->req.send_content == false) if (session->req.sent_headers && session->req.send_content == false) {
lprintf(LOG_INFO, "%04d %s [%s] Not sending data because session->req.send_content == false", session->socket, session->client.protocol, session->host_ip);
return 0; return 0;
}
while (sent < len) { while (sent < len) {
ResetEvent(session->outbuf.empty_event); ResetEvent(session->outbuf.empty_event);
avail = RingBufFree(&session->outbuf); avail = RingBufFree(&session->outbuf);
...@@ -1632,7 +1634,7 @@ static void send_error(http_session_t * session, unsigned line, const char* mess ...@@ -1632,7 +1634,7 @@ static void send_error(http_session_t * session, unsigned line, const char* mess
else else
SAFEPRINTF2(session->req.physical_path, "%s%s.html", error_dir, error_code); SAFEPRINTF2(session->req.physical_path, "%s%s.html", error_dir, error_code);
session->req.mime_type = get_mime_type(strrchr(session->req.physical_path, '.')); session->req.mime_type = get_mime_type(strrchr(session->req.physical_path, '.'));
send_headers(session, message, false); if (send_headers(session, message, false) && session->req.send_content) {
if (!stat(session->req.physical_path, &sb)) { if (!stat(session->req.physical_path, &sb)) {
off_t snt = 0; off_t snt = 0;
snt = sock_sendfile(session, session->req.physical_path, 0, 0); snt = sock_sendfile(session, session->req.physical_path, 0, 0);
...@@ -1656,6 +1658,7 @@ static void send_error(http_session_t * session, unsigned line, const char* mess ...@@ -1656,6 +1658,7 @@ static void send_error(http_session_t * session, unsigned line, const char* mess
session->req.ld->size = strlen(sbuf); session->req.ld->size = strlen(sbuf);
} }
} }
}
drain_outbuf(session); drain_outbuf(session);
session->req.finished = true; session->req.finished = true;
} }
...@@ -6941,6 +6944,11 @@ void http_session_thread(void* arg) ...@@ -6941,6 +6944,11 @@ void http_session_thread(void* arg)
lprintf(LOG_NOTICE, "%04d %s [%s] New concurrent connections per client highwater mark: %u" lprintf(LOG_NOTICE, "%04d %s [%s] New concurrent connections per client highwater mark: %u"
, socket, session.client.protocol, session.host_ip, con_conn_highwater); , socket, session.client.protocol, session.host_ip, con_conn_highwater);
} }
/*
* If we don't parse a request method, assume GET / HTTP/1.0
*/
session.req.method = HTTP_GET;
session.http_ver = HTTP_1_0;
if (startup->max_concurrent_connections > 0) { if (startup->max_concurrent_connections > 0) {
if (connections > startup->max_concurrent_connections if (connections > startup->max_concurrent_connections
&& !is_host_exempt(&scfg, session.host_ip, /* host_name */ NULL)) { && !is_host_exempt(&scfg, session.host_ip, /* host_name */ NULL)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment