Skip to content

Commit

Permalink
Add 'allow-data-mutation' feature flag to expose 'local()' method in …
Browse files Browse the repository at this point in the history
…Request module
  • Loading branch information
martynp committed Jul 9, 2023
1 parent 9a9cd76 commit bfd943a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ secrets = ["rocket_http/private-cookies"]
json = ["serde_json", "tokio/io-util"]
msgpack = ["rmp-serde", "tokio/io-util"]
uuid = ["uuid_", "rocket_http/uuid"]
allow-data-mutation = []

[dependencies]
# Serialization dependencies.
Expand Down
11 changes: 11 additions & 0 deletions core/lib/src/data/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ impl<'r> Data<'r> {
}

/// This creates a `data` object from a local data source `data`.
#[cfg(feature = "allow-data-mutation")]
#[inline]
pub fn local(data: Vec<u8>) -> Data<'r> {
Data {
buffer: data,
stream: StreamReader::empty(),
is_complete: true,
}
}

#[cfg(not(feature = "allow-data-mutation"))]
#[inline]
pub(crate) fn local(data: Vec<u8>) -> Data<'r> {
Data {
Expand Down
7 changes: 7 additions & 0 deletions core/lib/src/request/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct Request<'r> {
method: Atomic<Method>,
uri: Origin<'r>,
headers: HeaderMap<'r>,
/// Additional data added before request is processed
#[cfg(feature = "allow-data-mutation")]
pub meta: std::collections::HashMap<String, String>,
pub(crate) connection: ConnectionMeta,
pub(crate) state: RequestState<'r>,
}
Expand Down Expand Up @@ -58,6 +61,8 @@ impl Request<'_> {
method: Atomic::new(self.method()),
uri: self.uri.clone(),
headers: self.headers.clone(),
#[cfg(feature = "allow-data-mutation")]
meta: self.meta.clone(),
connection: self.connection.clone(),
state: self.state.clone(),
}
Expand Down Expand Up @@ -90,6 +95,8 @@ impl<'r> Request<'r> {
uri,
method: Atomic::new(method),
headers: HeaderMap::new(),
#[cfg(feature = "allow-data-mutation")]
meta: std::collections::HashMap::new(),
connection: ConnectionMeta {
remote: None,
client_certificates: None,
Expand Down

0 comments on commit bfd943a

Please sign in to comment.