Retrieve the optional file associated with a Request
The sever is now able to get any optional file descriptor that might have been sent over with the bytes related to a request. This patch leverages this ability by extending the Request structure with an optional File, which might have been received from the byte stream. With the Request containing an optional File, we give the consumers of this crate the possibility to receive a file descriptor associated with the HTTP request. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
georgepisaltu
parent
3c4cc3aa91
commit
9517a30037
@@ -1,6 +1,7 @@
|
||||
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::fs::File;
|
||||
use std::str::from_utf8;
|
||||
|
||||
use crate::common::ascii::{CR, CRLF_LEN, LF, SP};
|
||||
@@ -158,6 +159,8 @@ pub struct Request {
|
||||
pub headers: Headers,
|
||||
/// The body of the request.
|
||||
pub body: Option<Body>,
|
||||
/// The optional file associated with the request.
|
||||
pub file: Option<File>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
@@ -217,6 +220,7 @@ impl Request {
|
||||
request_line,
|
||||
headers: Headers::default(),
|
||||
body: None,
|
||||
file: None,
|
||||
}),
|
||||
Some(headers_end) => {
|
||||
// Parse the request headers.
|
||||
@@ -276,6 +280,7 @@ impl Request {
|
||||
request_line,
|
||||
headers,
|
||||
body,
|
||||
file: None,
|
||||
})
|
||||
}
|
||||
// If we can't find a CR LF CR LF even though the request should have headers
|
||||
@@ -444,6 +449,7 @@ mod tests {
|
||||
uri: Uri::new("http://localhost/home"),
|
||||
},
|
||||
body: None,
|
||||
file: None,
|
||||
headers: Headers::default(),
|
||||
};
|
||||
let request_bytes = b"GET http://localhost/home HTTP/1.0\r\n\
|
||||
|
||||
Reference in New Issue
Block a user