mirror of https://github.com/nealey/eris.git
Print HTTP results on timeouts
This commit is contained in:
parent
7995aed5bb
commit
49f6374ff0
9
cgi.c
9
cgi.c
|
@ -4,6 +4,14 @@ sigchld(int sig)
|
||||||
while (waitpid(0, NULL, WNOHANG) > 0);
|
while (waitpid(0, NULL, WNOHANG) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sigalarm_cgi(int sig)
|
||||||
|
{
|
||||||
|
/* send this out regardless of whether we've already sent a header,
|
||||||
|
* to maybe help with debugging */
|
||||||
|
badrequest(504, "Gateway Timeout", "The CGI is being too slow.");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cgi_child(const char *relpath)
|
cgi_child(const char *relpath)
|
||||||
{
|
{
|
||||||
|
@ -165,6 +173,7 @@ serve_cgi(char *relpath)
|
||||||
keepalive = 0;
|
keepalive = 0;
|
||||||
|
|
||||||
alarm(CGI_TIMEOUT);
|
alarm(CGI_TIMEOUT);
|
||||||
|
signal(SIGALRM, sigalarm_cgi);
|
||||||
cgi_parent(cin[0], cout[1], 0);
|
cgi_parent(cin[0], cout[1], 0);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
12
eris.c
12
eris.c
|
@ -98,6 +98,7 @@ char *path;
|
||||||
int http_version;
|
int http_version;
|
||||||
char *content_type;
|
char *content_type;
|
||||||
size_t content_length;
|
size_t content_length;
|
||||||
|
int header_sent;
|
||||||
off_t range_start, range_end;
|
off_t range_start, range_end;
|
||||||
time_t ims = 0;
|
time_t ims = 0;
|
||||||
|
|
||||||
|
@ -143,6 +144,7 @@ dolog(int code, off_t len)
|
||||||
void
|
void
|
||||||
header(unsigned int code, const char *httpcomment)
|
header(unsigned int code, const char *httpcomment)
|
||||||
{
|
{
|
||||||
|
header_sent = 1;
|
||||||
printf("HTTP/1.%d %u %s\r\n", http_version, code, httpcomment);
|
printf("HTTP/1.%d %u %s\r\n", http_version, code, httpcomment);
|
||||||
printf("Server: " FNORD "\r\n");
|
printf("Server: " FNORD "\r\n");
|
||||||
printf("Connection: %s\r\n", keepalive?"keep-alive":"close");
|
printf("Connection: %s\r\n", keepalive?"keep-alive":"close");
|
||||||
|
@ -519,6 +521,7 @@ handle_request()
|
||||||
range_end = 0;
|
range_end = 0;
|
||||||
content_type = NULL;
|
content_type = NULL;
|
||||||
content_length = 0;
|
content_length = 0;
|
||||||
|
header_sent = 0;
|
||||||
|
|
||||||
alarm(READTIMEOUT);
|
alarm(READTIMEOUT);
|
||||||
|
|
||||||
|
@ -746,6 +749,14 @@ handle_request()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sigalarm(int sig)
|
||||||
|
{
|
||||||
|
if (! header_sent) {
|
||||||
|
badrequest(408, "Request Timeout", "You are being too slow.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[], const char *const *envp)
|
main(int argc, char *argv[], const char *const *envp)
|
||||||
{
|
{
|
||||||
|
@ -756,6 +767,7 @@ main(int argc, char *argv[], const char *const *envp)
|
||||||
setbuffer(stdout, stdout_buf, sizeof stdout_buf);
|
setbuffer(stdout, stdout_buf, sizeof stdout_buf);
|
||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
signal(SIGALRM, sigalarm);
|
||||||
get_ucspi_env();
|
get_ucspi_env();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
10
test.sh
10
test.sh
|
@ -124,7 +124,6 @@ title "Too many headers"
|
||||||
printf '\r\n') | $HTTPD 2>/dev/null | grep -q 'HTTP/1.. 431 ' && pass || fail
|
printf '\r\n') | $HTTPD 2>/dev/null | grep -q 'HTTP/1.. 431 ' && pass || fail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
H "If-Modified-Since"
|
H "If-Modified-Since"
|
||||||
|
|
||||||
title "Has been modified"
|
title "Has been modified"
|
||||||
|
@ -189,6 +188,15 @@ printf 'GET /a.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | d | grep -Eq '%S
|
||||||
title "Large response"
|
title "Large response"
|
||||||
printf 'GET /mongo.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | grep -q james && pass || fail
|
printf 'GET /mongo.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | grep -q james && pass || fail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
H "Timeouts"
|
||||||
|
|
||||||
|
title "Read timeout"
|
||||||
|
(sleep 2.1; echo) | $HTTPD 2>&1 | grep -c 'HTTP/1.. 408 \|.null. 408' | grep -q 2 && pass || fail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
H "fnord bugs"
|
H "fnord bugs"
|
||||||
|
|
||||||
# 1. Should return directory listing of /; instead segfaults
|
# 1. Should return directory listing of /; instead segfaults
|
||||||
|
|
Loading…
Reference in New Issue