add servicerequest::conn_data

This commit is contained in:
Rob Ede 2021-12-07 17:15:25 +00:00
parent 9569860940
commit 7d5ccb4c46
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 12 additions and 6 deletions

View File

@ -172,12 +172,10 @@ impl ServiceRequest {
self.head().uri.path() self.head().uri.path()
} }
/// The query string in the URL. /// Counterpart to [`HttpRequest::query_string`](super::HttpRequest::query_string()).
///
/// E.g., id=10
#[inline] #[inline]
pub fn query_string(&self) -> &str { pub fn query_string(&self) -> &str {
self.uri().query().unwrap_or_default() self.req.query_string()
} }
/// Peer socket address. /// Peer socket address.
@ -241,6 +239,7 @@ impl ServiceRequest {
} }
/// Counterpart to [`HttpRequest::app_data`](super::HttpRequest::app_data()). /// Counterpart to [`HttpRequest::app_data`](super::HttpRequest::app_data()).
#[inline]
pub fn app_data<T: 'static>(&self) -> Option<&T> { pub fn app_data<T: 'static>(&self) -> Option<&T> {
for container in self.req.inner.app_data.iter().rev() { for container in self.req.inner.app_data.iter().rev() {
if let Some(data) = container.get::<T>() { if let Some(data) = container.get::<T>() {
@ -251,6 +250,12 @@ impl ServiceRequest {
None None
} }
/// Counterpart to [`HttpRequest::conn_data`](super::HttpRequest::conn_data()).
#[inline]
pub fn conn_data<T: 'static>(&self) -> Option<&T> {
self.req.conn_data()
}
#[cfg(feature = "cookies")] #[cfg(feature = "cookies")]
pub fn cookies(&self) -> Result<Ref<'_, Vec<Cookie<'static>>>, CookieParseError> { pub fn cookies(&self) -> Result<Ref<'_, Vec<Cookie<'static>>>, CookieParseError> {
self.req.cookies() self.req.cookies()
@ -263,6 +268,7 @@ impl ServiceRequest {
} }
/// Set request payload. /// Set request payload.
#[inline]
pub fn set_payload(&mut self, payload: Payload) { pub fn set_payload(&mut self, payload: Payload) {
self.payload = payload; self.payload = payload;
} }
@ -280,6 +286,7 @@ impl ServiceRequest {
} }
impl Resource<Url> for ServiceRequest { impl Resource<Url> for ServiceRequest {
#[inline]
fn resource_path(&mut self) -> &mut Path<Url> { fn resource_path(&mut self) -> &mut Path<Url> {
self.match_info_mut() self.match_info_mut()
} }
@ -404,12 +411,11 @@ impl<B> ServiceResponse<B> {
} }
/// Extract response body /// Extract response body
#[inline]
pub fn into_body(self) -> B { pub fn into_body(self) -> B {
self.response.into_body() self.response.into_body()
} }
}
impl<B> ServiceResponse<B> {
/// Set a new body /// Set a new body
#[inline] #[inline]
pub fn map_body<F, B2>(self, f: F) -> ServiceResponse<B2> pub fn map_body<F, B2>(self, f: F) -> ServiceResponse<B2>