Struct cosworth::prelude::HttpRequest
source · pub struct HttpRequest<S = ()> { /* private fields */ }
Expand description
An HTTP Request
Implementations§
source§impl<S> HttpRequest<S>
impl<S> HttpRequest<S>
sourcepub fn drop_state(&self) -> HttpRequest<()>
pub fn drop_state(&self) -> HttpRequest<()>
Construct new http request with empty state.
sourcepub fn extensions(&self) -> Ref<'_, Extensions>
pub fn extensions(&self) -> Ref<'_, Extensions>
Request extensions
sourcepub fn extensions_mut(&self) -> RefMut<'_, Extensions>
pub fn extensions_mut(&self) -> RefMut<'_, Extensions>
Mutable reference to a the request’s extensions
sourcepub fn response(&self, status: StatusCode, body: Body) -> HttpResponse
pub fn response(&self, status: StatusCode, body: Body) -> HttpResponse
Create http response
sourcepub fn build_response(&self, status: StatusCode) -> HttpResponseBuilder
pub fn build_response(&self, status: StatusCode) -> HttpResponseBuilder
Create http response builder
sourcepub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
pub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
Get ConnectionInfo for the correct request.
sourcepub fn url_for<U, I>(
&self,
name: &str,
elements: U
) -> Result<Url, UrlGenerationError>where
U: IntoIterator<Item = I>,
I: AsRef<str>,
pub fn url_for<U, I>(
&self,
name: &str,
elements: U
) -> Result<Url, UrlGenerationError>where
U: IntoIterator<Item = I>,
I: AsRef<str>,
Generate url for named resource
fn index(req: HttpRequest) -> HttpResponse {
let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource
HttpResponse::Ok().into()
}
fn main() {
let app = App::new()
.resource("/test/{one}/{two}/{three}", |r| {
r.name("foo"); // <- set resource name, then it could be used in `url_for`
r.method(http::Method::GET).f(|_| HttpResponse::Ok());
})
.finish();
}
sourcepub fn url_for_static(&self, name: &str) -> Result<Url, UrlGenerationError>
pub fn url_for_static(&self, name: &str) -> Result<Url, UrlGenerationError>
Generate url for named resource
This method is similar to HttpRequest::url_for()
but it can be used
for urls that do not contain variable parts.
sourcepub fn resource(&self) -> &ResourceInfo
pub fn resource(&self) -> &ResourceInfo
This method returns reference to current ResourceInfo
object.
sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
Peer socket address
Peer address is actual socket address, if proxy is used in front of actix http server, then peer address would be address of this proxy.
To get client connection information connection_info()
method should
be used.
sourcepub fn query_string(&self) -> &str
pub fn query_string(&self) -> &str
The query string in the URL.
E.g., id=10
Load request cookies.
Return request cookie.
sourcepub fn match_info(&self) -> &Params
pub fn match_info(&self) -> &Params
Get a reference to the Params object.
Params is a container for url parameters.
A variable segment is specified in the form {identifier}
,
where the identifier can be used later in a request handler to
access the matched value for that segment.
sourcepub fn set_read_buffer_capacity(&mut self, cap: usize)
pub fn set_read_buffer_capacity(&mut self, cap: usize)
Set read buffer capacity
Default buffer capacity is 32Kb.
Methods from Deref<Target = Request>§
sourcepub fn headers(&self) -> &HeaderMap<HeaderValue>
pub fn headers(&self) -> &HeaderMap<HeaderValue>
Returns Request’s headers.
sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
Peer socket address
Peer address is actual socket address, if proxy is used in front of actix http server, then peer address would be address of this proxy.
To get client connection information connection_info()
method should
be used.
sourcepub fn keep_alive(&self) -> bool
pub fn keep_alive(&self) -> bool
Checks if a connection should be kept alive.
sourcepub fn extensions(&self) -> Ref<'_, Extensions>
pub fn extensions(&self) -> Ref<'_, Extensions>
Request extensions
sourcepub fn extensions_mut(&self) -> RefMut<'_, Extensions>
pub fn extensions_mut(&self) -> RefMut<'_, Extensions>
Mutable reference to a the request’s extensions
sourcepub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
pub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
Get ConnectionInfo for the correct request.
sourcepub fn stream_extensions(&self) -> Option<&Extensions>
pub fn stream_extensions(&self) -> Option<&Extensions>
Io stream extensions
sourcepub fn server_settings(&self) -> &ServerSettings
pub fn server_settings(&self) -> &ServerSettings
Server settings
Trait Implementations§
source§impl<S> Clone for HttpRequest<S>
impl<S> Clone for HttpRequest<S>
source§fn clone(&self) -> HttpRequest<S>
fn clone(&self) -> HttpRequest<S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<S> Debug for HttpRequest<S>
impl<S> Debug for HttpRequest<S>
source§impl<S> Deref for HttpRequest<S>
impl<S> Deref for HttpRequest<S>
source§impl<S> Drop for HttpRequest<S>
impl<S> Drop for HttpRequest<S>
source§impl<S> FromRequest<S> for HttpRequest<S>
impl<S> FromRequest<S> for HttpRequest<S>
§type Result = HttpRequest<S>
type Result = HttpRequest<S>
source§fn from_request(
req: &HttpRequest<S>,
_: &<HttpRequest<S> as FromRequest<S>>::Config
) -> <HttpRequest<S> as FromRequest<S>>::Result
fn from_request(
req: &HttpRequest<S>,
_: &<HttpRequest<S> as FromRequest<S>>::Config
) -> <HttpRequest<S> as FromRequest<S>>::Result
source§impl<S> HttpMessage for HttpRequest<S>
impl<S> HttpMessage for HttpRequest<S>
source§fn headers(&self) -> &HeaderMap<HeaderValue>
fn headers(&self) -> &HeaderMap<HeaderValue>
source§fn content_type(&self) -> &str
fn content_type(&self) -> &str
source§fn encoding(
&self
) -> Result<&'static (dyn Encoding + Send + Sync + 'static), ContentTypeError>
fn encoding(
&self
) -> Result<&'static (dyn Encoding + Send + Sync + 'static), ContentTypeError>
source§fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
source§fn body(&self) -> MessageBody<Self>
fn body(&self) -> MessageBody<Self>
source§fn urlencoded<T>(&self) -> UrlEncoded<Self, T>where
T: DeserializeOwned,
fn urlencoded<T>(&self) -> UrlEncoded<Self, T>where
T: DeserializeOwned,
application/x-www-form-urlencoded
encoded request’s body.
Return UrlEncoded
future. Form can be deserialized to any type that
implements Deserialize
trait from serde. Read moresource§fn json<T>(&self) -> JsonBody<Self, T>where
T: DeserializeOwned,
fn json<T>(&self) -> JsonBody<Self, T>where
T: DeserializeOwned,
source§impl<S> RequestIdentity for HttpRequest<S>
impl<S> RequestIdentity for HttpRequest<S>
source§impl<S> RequestSession for HttpRequest<S>
impl<S> RequestSession for HttpRequest<S>
Auto Trait Implementations§
impl<S = ()> !RefUnwindSafe for HttpRequest<S>
impl<S = ()> !Send for HttpRequest<S>
impl<S = ()> !Sync for HttpRequest<S>
impl<S> Unpin for HttpRequest<S>
impl<S = ()> !UnwindSafe for HttpRequest<S>
Blanket Implementations§
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
&self
to an expression for Diesel’s query builder. Read more