mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Don't include URL or method in default_reply.
This commit is contained in:
parent
3058f910d9
commit
dc0fd7ecdc
26
darkhttpd.c
26
darkhttpd.c
@ -1994,7 +1994,7 @@ static void process_get(struct connection *conn) {
|
|||||||
/* make sure it's safe */
|
/* make sure it's safe */
|
||||||
if (make_safe_url(decoded_url) == NULL) {
|
if (make_safe_url(decoded_url) == NULL) {
|
||||||
default_reply(conn, 400, "Bad Request",
|
default_reply(conn, 400, "Bad Request",
|
||||||
"You requested an invalid URL: %s", conn->url);
|
"You requested an invalid URL.");
|
||||||
free(decoded_url);
|
free(decoded_url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2036,7 +2036,7 @@ static void process_get(struct connection *conn) {
|
|||||||
* i.e.: Don't leak information.
|
* i.e.: Don't leak information.
|
||||||
*/
|
*/
|
||||||
default_reply(conn, 404, "Not Found",
|
default_reply(conn, 404, "Not Found",
|
||||||
"The URL you requested (%s) was not found.", conn->url);
|
"The URL you requested was not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xasprintf(&target, "%s%s", wwwroot, decoded_url);
|
xasprintf(&target, "%s%s", wwwroot, decoded_url);
|
||||||
@ -2065,14 +2065,14 @@ static void process_get(struct connection *conn) {
|
|||||||
/* open() failed */
|
/* open() failed */
|
||||||
if (errno == EACCES)
|
if (errno == EACCES)
|
||||||
default_reply(conn, 403, "Forbidden",
|
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)
|
else if (errno == ENOENT)
|
||||||
default_reply(conn, 404, "Not Found",
|
default_reply(conn, 404, "Not Found",
|
||||||
"The URL you requested (%s) was not found.", conn->url);
|
"The URL you requested was not found.");
|
||||||
else
|
else
|
||||||
default_reply(conn, 500, "Internal Server Error",
|
default_reply(conn, 500, "Internal Server Error",
|
||||||
"The URL you requested (%s) cannot be returned: %s.",
|
"The URL you requested cannot be returned: %s.",
|
||||||
conn->url, strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2230,19 +2230,9 @@ static void process_request(struct connection *conn) {
|
|||||||
process_get(conn);
|
process_get(conn);
|
||||||
conn->header_only = 1;
|
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 {
|
else {
|
||||||
default_reply(conn, 400, "Bad Request",
|
default_reply(conn, 501, "Not Implemented",
|
||||||
"%s is not a valid HTTP/1.1 method.", conn->method);
|
"The method you specified is not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* advance state */
|
/* advance state */
|
||||||
|
@ -120,8 +120,6 @@ class TestHelper(unittest.TestCase):
|
|||||||
|
|
||||||
def assertIsIndex(self, body, path):
|
def assertIsIndex(self, body, path):
|
||||||
self.assertContains(body,
|
self.assertContains(body,
|
||||||
"<title>%s</title>\n"%path,
|
|
||||||
"<h1>%s</h1>\n"%path,
|
|
||||||
'<a href="..">..</a>/',
|
'<a href="..">..</a>/',
|
||||||
'Generated by darkhttpd')
|
'Generated by darkhttpd')
|
||||||
|
|
||||||
@ -129,21 +127,21 @@ class TestHelper(unittest.TestCase):
|
|||||||
self.assertContains(body,
|
self.assertContains(body,
|
||||||
"<title>400 Bad Request</title>",
|
"<title>400 Bad Request</title>",
|
||||||
"<h1>Bad Request</h1>\n",
|
"<h1>Bad Request</h1>\n",
|
||||||
"You requested an invalid URL: %s\n"%path,
|
"You requested an invalid URL.\n",
|
||||||
'Generated by darkhttpd')
|
'Generated by darkhttpd')
|
||||||
|
|
||||||
def assertNotFound(self, body, path):
|
def assertNotFound(self, body, path):
|
||||||
self.assertContains(body,
|
self.assertContains(body,
|
||||||
"<title>404 Not Found</title>",
|
"<title>404 Not Found</title>",
|
||||||
"<h1>Not Found</h1>\n",
|
"<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')
|
'Generated by darkhttpd')
|
||||||
|
|
||||||
def assertForbidden(self, body, path):
|
def assertForbidden(self, body, path):
|
||||||
self.assertContains(body,
|
self.assertContains(body,
|
||||||
"<title>403 Forbidden</title>",
|
"<title>403 Forbidden</title>",
|
||||||
"<h1>Forbidden</h1>\n",
|
"<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')
|
'Generated by darkhttpd')
|
||||||
|
|
||||||
def assertUnreadable(self, body, path):
|
def assertUnreadable(self, body, path):
|
||||||
|
@ -7,7 +7,7 @@ class TestForward(TestHelper):
|
|||||||
def test_no_server_id(self):
|
def test_no_server_id(self):
|
||||||
resp = self.get('/', method = 'BOGUS')
|
resp = self.get('/', method = 'BOGUS')
|
||||||
status, hdrs, body = parse(resp)
|
status, hdrs, body = parse(resp)
|
||||||
self.assertContains(status, "400 Bad Request")
|
self.assertContains(status, "501 Not Implemented")
|
||||||
self.assertFalse('Server' in hdrs)
|
self.assertFalse('Server' in hdrs)
|
||||||
self.assertFalse(b'Generated by darkhttpd/' in body)
|
self.assertFalse(b'Generated by darkhttpd/' in body)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user