Add support for the HTTP DELETE method
Add a Delete variant to the Method enum to support DELETE requests. Reject DELETE requests with a body (same as GET requests). Signed-off-by: Ilias Stamatis <ilstam@amazon.com>
This commit is contained in:
committed by
Ilias Stamatis
parent
9228ffdcc5
commit
876f3feccc
@@ -249,7 +249,9 @@ impl Request {
|
||||
None
|
||||
}
|
||||
content_length => {
|
||||
if request_line.method == Method::Get {
|
||||
if request_line.method == Method::Get
|
||||
|| request_line.method == Method::Delete
|
||||
{
|
||||
return Err(RequestError::InvalidRequest);
|
||||
}
|
||||
// Multiplication is safe because `CRLF_LEN` is a small constant.
|
||||
@@ -483,6 +485,15 @@ mod tests {
|
||||
RequestError::InvalidRequest
|
||||
);
|
||||
|
||||
// Test for invalid Request (`DELETE` requests should have no body).
|
||||
let request_bytes = b"DELETE /machine-config HTTP/1.1\r\n\
|
||||
Content-Length: 13\r\n\
|
||||
Content-Type: application/json\r\n\r\nwhatever body";
|
||||
assert_eq!(
|
||||
Request::try_from(request_bytes, None).unwrap_err(),
|
||||
RequestError::InvalidRequest
|
||||
);
|
||||
|
||||
// Test for request larger than maximum len provided.
|
||||
let request_bytes = b"GET http://localhost/home HTTP/1.0\r\n\
|
||||
Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT\r\n\r\n";
|
||||
|
||||
Reference in New Issue
Block a user