mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
cleanup mut transform
This commit is contained in:
parent
6ec8352612
commit
a5bbc455c0
@ -1251,16 +1251,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_redirect_to_index_nested() {
|
||||
let mut st = StaticFiles::new(".").index_file("Cargo.toml");
|
||||
let mut st = StaticFiles::new(".").index_file("mod.rs");
|
||||
let mut req = HttpRequest::default();
|
||||
req.match_info_mut().add("tail", "tools/wsload");
|
||||
req.match_info_mut().add("tail", "src/client");
|
||||
|
||||
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
|
||||
let resp = resp.as_msg();
|
||||
assert_eq!(resp.status(), StatusCode::FOUND);
|
||||
assert_eq!(
|
||||
resp.headers().get(header::LOCATION).unwrap(),
|
||||
"/tools/wsload/Cargo.toml"
|
||||
"/src/client/mod.rs"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -170,23 +170,16 @@ impl<S> HttpRequest<S> {
|
||||
|
||||
/// get mutable reference for inner message
|
||||
/// mutable reference should not be returned as result for request's method
|
||||
#[inline(always)]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref, inline_always))]
|
||||
pub(crate) fn as_mut(&self) -> &mut HttpInnerMessage {
|
||||
#[inline]
|
||||
pub(crate) fn as_mut(&mut self) -> &mut HttpInnerMessage {
|
||||
self.0.get_mut()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref, inline_always))]
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &HttpInnerMessage {
|
||||
self.0.get_ref()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn get_inner(&mut self) -> &mut HttpInnerMessage {
|
||||
self.as_mut()
|
||||
}
|
||||
|
||||
/// Shared application state
|
||||
#[inline]
|
||||
pub fn state(&self) -> &S {
|
||||
@ -278,7 +271,8 @@ impl<S> HttpRequest<S> {
|
||||
/// Get *ConnectionInfo* for correct request.
|
||||
pub fn connection_info(&self) -> &ConnectionInfo {
|
||||
if self.extensions().get::<Info>().is_none() {
|
||||
self.as_mut()
|
||||
let mut req = self.clone();
|
||||
req.as_mut()
|
||||
.extensions
|
||||
.insert(Info(ConnectionInfo::new(self)));
|
||||
}
|
||||
@ -384,7 +378,8 @@ impl<S> HttpRequest<S> {
|
||||
for (key, val) in form_urlencoded::parse(self.query_string().as_ref()) {
|
||||
query.insert(key.as_ref().to_string(), val.to_string());
|
||||
}
|
||||
self.as_mut().extensions.insert(Query(query));
|
||||
let mut req = self.clone();
|
||||
req.as_mut().extensions.insert(Query(query));
|
||||
}
|
||||
&self.extensions().get::<Query>().unwrap().0
|
||||
}
|
||||
@ -404,7 +399,8 @@ impl<S> HttpRequest<S> {
|
||||
/// Load request cookies.
|
||||
pub fn cookies(&self) -> Result<&Vec<Cookie<'static>>, CookieParseError> {
|
||||
if self.extensions().get::<Query>().is_none() {
|
||||
let msg = self.as_mut();
|
||||
let mut req = self.clone();
|
||||
let msg = req.as_mut();
|
||||
let mut cookies = Vec::new();
|
||||
for hdr in msg.headers.get_all(header::COOKIE) {
|
||||
let s = str::from_utf8(hdr.as_bytes()).map_err(CookieParseError::from)?;
|
||||
@ -479,7 +475,7 @@ impl<S> HttpRequest<S> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn payload(&self) -> &Payload {
|
||||
pub(crate) fn payload(&mut self) -> &Payload {
|
||||
let msg = self.as_mut();
|
||||
if msg.payload.is_none() {
|
||||
msg.payload = Some(Payload::empty());
|
||||
|
@ -487,7 +487,7 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
||||
self.resp.content_encoding().unwrap_or(info.encoding);
|
||||
|
||||
let result = match io.start(
|
||||
info.req_mut().get_inner(),
|
||||
info.req_mut().as_mut(),
|
||||
&mut self.resp,
|
||||
encoding,
|
||||
) {
|
||||
|
@ -306,7 +306,7 @@ where
|
||||
pub fn parse(&mut self) {
|
||||
'outer: loop {
|
||||
match self.decoder.decode(&mut self.buf, &self.settings) {
|
||||
Ok(Some(Message::Message { msg, payload })) => {
|
||||
Ok(Some(Message::Message { mut msg, payload })) => {
|
||||
self.flags.insert(Flags::STARTED);
|
||||
|
||||
if payload {
|
||||
|
@ -120,7 +120,7 @@ impl H1Decoder {
|
||||
let slice = buf.split_to(len).freeze();
|
||||
|
||||
// convert headers
|
||||
let msg = settings.get_http_message();
|
||||
let mut msg = settings.get_http_message();
|
||||
{
|
||||
let msg_mut = msg.get_mut();
|
||||
msg_mut
|
||||
|
@ -307,7 +307,7 @@ impl<H: 'static> Entry<H> {
|
||||
// Payload and Content-Encoding
|
||||
let (psender, payload) = Payload::new(false);
|
||||
|
||||
let msg = settings.get_http_message();
|
||||
let mut msg = settings.get_http_message();
|
||||
msg.get_mut().url = Url::new(parts.uri);
|
||||
msg.get_mut().method = parts.method;
|
||||
msg.get_mut().version = parts.version;
|
||||
|
@ -74,16 +74,13 @@ impl SharedHttpInnerMessage {
|
||||
SharedHttpInnerMessage(Some(msg), Some(pool))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(mutable_transmutes)]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref, inline_always))]
|
||||
pub fn get_mut(&self) -> &mut HttpInnerMessage {
|
||||
#[inline]
|
||||
pub fn get_mut(&mut self) -> &mut HttpInnerMessage {
|
||||
let r: &HttpInnerMessage = self.0.as_ref().unwrap().as_ref();
|
||||
unsafe { &mut *(r as *const _ as *mut _) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(inline_always))]
|
||||
#[inline]
|
||||
pub fn get_ref(&self) -> &HttpInnerMessage {
|
||||
self.0.as_ref().unwrap()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user