Don't include URL or method in default_reply.

This commit is contained in:
Emil Mikulic 2021-02-21 17:02:39 +11:00
parent 3058f910d9
commit dc0fd7ecdc
3 changed files with 12 additions and 24 deletions

View File

@ -1994,7 +1994,7 @@ static void process_get(struct connection *conn) {
/* make sure it's safe */
if (make_safe_url(decoded_url) == NULL) {
default_reply(conn, 400, "Bad Request",
"You requested an invalid URL: %s", conn->url);
"You requested an invalid URL.");
free(decoded_url);
return;
}
@ -2036,7 +2036,7 @@ static void process_get(struct connection *conn) {
* i.e.: Don't leak information.
*/
default_reply(conn, 404, "Not Found",
"The URL you requested (%s) was not found.", conn->url);
"The URL you requested was not found.");
return;
}
xasprintf(&target, "%s%s", wwwroot, decoded_url);
@ -2065,14 +2065,14 @@ static void process_get(struct connection *conn) {
/* open() failed */
if (errno == EACCES)
default_reply(conn, 403, "Forbidden",
"You don't have permission to access (%s).", conn->url);
"You don't have permission to access this URL.");
else if (errno == ENOENT)
default_reply(conn, 404, "Not Found",
"The URL you requested (%s) was not found.", conn->url);
"The URL you requested was not found.");
else
default_reply(conn, 500, "Internal Server Error",
"The URL you requested (%s) cannot be returned: %s.",
conn->url, strerror(errno));
"The URL you requested cannot be returned: %s.",
strerror(errno));
return;
}
@ -2230,19 +2230,9 @@ static void process_request(struct connection *conn) {
process_get(conn);
conn->header_only = 1;
}
else if ((strcmp(conn->method, "OPTIONS") == 0) ||
(strcmp(conn->method, "POST") == 0) ||
(strcmp(conn->method, "PUT") == 0) ||
(strcmp(conn->method, "DELETE") == 0) ||
(strcmp(conn->method, "TRACE") == 0) ||
(strcmp(conn->method, "CONNECT") == 0)) {
default_reply(conn, 501, "Not Implemented",
"The method you specified (%s) is not implemented.",
conn->method);
}
else {
default_reply(conn, 400, "Bad Request",
"%s is not a valid HTTP/1.1 method.", conn->method);
default_reply(conn, 501, "Not Implemented",
"The method you specified is not implemented.");
}
/* advance state */

View File

@ -120,8 +120,6 @@ class TestHelper(unittest.TestCase):
def assertIsIndex(self, body, path):
self.assertContains(body,
"<title>%s</title>\n"%path,
"<h1>%s</h1>\n"%path,
'<a href="..">..</a>/',
'Generated by darkhttpd')
@ -129,21 +127,21 @@ class TestHelper(unittest.TestCase):
self.assertContains(body,
"<title>400 Bad Request</title>",
"<h1>Bad Request</h1>\n",
"You requested an invalid URL: %s\n"%path,
"You requested an invalid URL.\n",
'Generated by darkhttpd')
def assertNotFound(self, body, path):
self.assertContains(body,
"<title>404 Not Found</title>",
"<h1>Not Found</h1>\n",
"The URL you requested (%s) was not found.\n"%path,
"The URL you requested was not found.\n",
'Generated by darkhttpd')
def assertForbidden(self, body, path):
self.assertContains(body,
"<title>403 Forbidden</title>",
"<h1>Forbidden</h1>\n",
"You don't have permission to access (%s).\n"%path,
"You don't have permission to access this URL.\n",
'Generated by darkhttpd')
def assertUnreadable(self, body, path):

View File

@ -7,7 +7,7 @@ class TestForward(TestHelper):
def test_no_server_id(self):
resp = self.get('/', method = 'BOGUS')
status, hdrs, body = parse(resp)
self.assertContains(status, "400 Bad Request")
self.assertContains(status, "501 Not Implemented")
self.assertFalse('Server' in hdrs)
self.assertFalse(b'Generated by darkhttpd/' in body)