[−][src]Struct http_types::Request
An HTTP request.
Examples
use http_types::{Url, Method, Request}; let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap()); req.set_body("Hello, Nori!");
Implementations
impl Request
[src]
pub fn new(method: Method, url: Url) -> Self
[src]
Create a new request.
pub fn method(&self) -> Method
[src]
Get the HTTP method
pub fn set_method(&mut self, method: Method)
[src]
Set the HTTP method.
pub fn url(&self) -> &Url
[src]
Get a reference to the url.
Examples
use http_types::{Url, Method, Request, Response, StatusCode}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); assert_eq!(req.url().scheme(), "https");
pub fn url_mut(&mut self) -> &mut Url
[src]
Get a mutable reference to the url.
Examples
use http_types::{Url, Method, Request, Response, StatusCode}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); req.url_mut().set_scheme("http"); assert_eq!(req.url().scheme(), "http");
pub fn set_body(&mut self, body: impl Into<Body>)
[src]
Set the request body.
Examples
use http_types::{Url, Method, Request}; let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap()); req.set_body("Hello, Nori!");
pub fn replace_body(&mut self, body: impl Into<Body>) -> Body
[src]
Swaps the value of the body with another body, without deinitializing either one.
Examples
use http_types::{Body, Url, Method, Request}; let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap()); req.set_body("Hello, Nori!"); let mut body: Body = req.replace_body("Hello, Chashu!"); let mut string = String::new(); body.read_to_string(&mut string).await?; assert_eq!(&string, "Hello, Nori!");
pub fn swap_body(&mut self, body: &mut Body)
[src]
Replace the request body with a new body, and return the old body.
Examples
use http_types::{Body, Url, Method, Request}; let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap()); req.set_body("Hello, Nori!"); let mut body = "Hello, Chashu!".into(); req.swap_body(&mut body); let mut string = String::new(); body.read_to_string(&mut string).await?; assert_eq!(&string, "Hello, Nori!");
pub fn take_body(&mut self) -> Body
[src]
Take the request body, replacing it with an empty body.
Examples
use http_types::{Body, Url, Method, Request}; let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap()); req.set_body("Hello, Nori!"); let mut body: Body = req.take_body(); let mut string = String::new(); body.read_to_string(&mut string).await?; assert_eq!(&string, "Hello, Nori!");
pub async fn body_string(self) -> Result<String>
[src]
Read the body as a string.
This consumes the request. If you want to read the body without
consuming the request, consider using the take_body
method and
then calling Body::into_string
or using the Request's AsyncRead
implementation to read the body.
Examples
use http_types::{Body, Url, Method, Request}; use async_std::io::Cursor; let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap()); let cursor = Cursor::new("Hello Nori"); let body = Body::from_reader(cursor, None); req.set_body(body); assert_eq!(&req.body_string().await.unwrap(), "Hello Nori");
pub fn header(&self, name: &HeaderName) -> Option<&Vec<HeaderValue>>
[src]
Get an HTTP header.
pub fn header_mut(&mut self, name: &HeaderName) -> Option<&mut Vec<HeaderValue>>
[src]
Get a mutable reference to a header.
pub fn remove_header(&mut self, name: &HeaderName) -> Option<Vec<HeaderValue>>
[src]
Remove a header.
pub fn insert_header(
&mut self,
name: impl TryInto<HeaderName>,
values: impl ToHeaderValues
) -> Result<Option<Vec<HeaderValue>>>
[src]
&mut self,
name: impl TryInto<HeaderName>,
values: impl ToHeaderValues
) -> Result<Option<Vec<HeaderValue>>>
Set an HTTP header.
Examples
use http_types::{Url, Method, Request}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); req.insert_header("Content-Type", "text/plain")?;
pub fn append_header(
&mut self,
name: impl TryInto<HeaderName>,
values: impl ToHeaderValues
) -> Result<()>
[src]
&mut self,
name: impl TryInto<HeaderName>,
values: impl ToHeaderValues
) -> Result<()>
Append a header to the headers.
Unlike insert
this function will not override the contents of a header, but insert a
header if there aren't any. Or else append to the existing list of headers.
Examples
use http_types::{Url, Method, Request}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); req.append_header("Content-Type", "text/plain")?;
pub fn set_content_type(&mut self, mime: Mime) -> Option<Vec<HeaderValue>>
[src]
Set the response MIME.
pub fn content_type(&self) -> Option<Mime>
[src]
Get the current content type
pub fn len(&self) -> Option<usize>
[src]
Get the length of the body stream, if it has been set.
This value is set when passing a fixed-size object into as the body. E.g. a string, or a
buffer. Consumers of this API should check this value to decide whether to use Chunked
encoding, or set the response length.
pub fn is_empty(&self) -> Option<bool>
[src]
Returns true
if the request has a set body stream length of zero, false
otherwise.
pub fn version(&self) -> Option<Version>
[src]
Get the HTTP version, if one has been set.
Examples
use http_types::{Url, Method, Request, Version}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); assert_eq!(req.version(), None); req.set_version(Some(Version::Http2_0)); assert_eq!(req.version(), Some(Version::Http2_0));
pub fn set_version(&mut self, version: Option<Version>)
[src]
Set the HTTP version.
Examples
use http_types::{Url, Method, Request, Version}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); req.set_version(Some(Version::Http2_0));
pub fn cookies(&self) -> Result<Vec<Cookie>, Error>
[src]
Get all cookies.
Examples
use http_types::{Cookie, Url, Method, Request, Version}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); req.set_cookie(Cookie::new("name", "value")); assert_eq!(req.cookies().unwrap(), vec![Cookie::new("name", "value")]);
pub fn cookie(&self, name: &str) -> Result<Option<Cookie>, Error>
[src]
Get a cookie by name.
Examples
use http_types::{Cookie, Url, Method, Request, Version}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); req.set_cookie(Cookie::new("name", "value")); assert_eq!(req.cookie("name").unwrap(), Some(Cookie::new("name", "value")));
pub fn set_cookie(&mut self, cookie: Cookie)
[src]
Set a cookie.
This will not override any existing cookies, and uses the Cookies
header.
Examples
use http_types::{Cookie, Url, Method, Request, Version}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); req.set_cookie(Cookie::new("name", "value"));
pub fn send_trailers(&mut self) -> TrailersSender
[src]
Sends trailers to the a receiver.
pub async fn recv_trailers<'_>(&'_ self) -> Option<Result<Trailers>>
[src]
Receive trailers from a sender.
pub fn iter(&self) -> Iter
[src]
An iterator visiting all header pairs in arbitrary order.
pub fn iter_mut(&mut self) -> IterMut
[src]
An iterator visiting all header pairs in arbitrary order, with mutable references to the values.
pub fn header_names(&self) -> Names
[src]
An iterator visiting all header names in arbitrary order.
pub fn header_values(&self) -> Values
[src]
An iterator visiting all header values in arbitrary order.
pub fn local(&self) -> &TypeMap
[src]
Returns a reference to the existing local state.
pub fn local_mut(&mut self) -> &mut TypeMap
[src]
Returns a mutuable reference to the existing local state.
Examples
use http_types::{Url, Method, Request, Version}; let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); req.local_mut().insert("hello from the extension"); assert_eq!(req.local().get(), Some(&"hello from the extension"));
Trait Implementations
impl AsMut<Headers> for Request
[src]
impl AsRef<Headers> for Request
[src]
impl AsyncBufRead for Request
[src]
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<&[u8]>>
[src]
fn consume(self: Pin<&mut Self>, amt: usize)
[src]
impl AsyncRead for Request
[src]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
impl Debug for Request
[src]
impl From<Request> for Body
[src]
impl IntoIterator for Request
[src]
type Item = (HeaderName, Vec<HeaderValue>)
The type of the elements being iterated over.
type IntoIter = IntoIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
Returns a iterator of references over the remaining items.
impl<'a> IntoIterator for &'a Request
[src]
type Item = (&'a HeaderName, &'a Vec<HeaderValue>)
The type of the elements being iterated over.
type IntoIter = Iter<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a> IntoIterator for &'a mut Request
[src]
type Item = (&'a HeaderName, &'a mut Vec<HeaderValue>)
The type of the elements being iterated over.
type IntoIter = IterMut<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'__pin> Unpin for Request where
__Origin<'__pin>: Unpin,
[src]
__Origin<'__pin>: Unpin,
Auto Trait Implementations
impl !RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl !UnwindSafe for Request
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<R> AsyncBufReadExt for R where
R: AsyncBufRead + ?Sized,
[src]
R: AsyncBufRead + ?Sized,
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntil<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntil<'a, Self> where
Self: Unpin,
fn read_line(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn lines(self) -> Lines<Self>
[src]
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
[src]
R: AsyncRead + ?Sized,
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
[src]
R: AsyncRead,
fn read(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_to_string(&'a mut self, buf: &'a mut String) -> ReadToString<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>) where
Self: AsyncWrite,
[src]
Self: AsyncWrite,
fn take(self, limit: u64) -> Take<Self>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> BufReadExt for T where
T: AsyncBufRead + ?Sized,
[src]
T: AsyncBufRead + ?Sized,
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<'a, Self> where
Self: Unpin,
fn read_line(&'a mut self, buf: &'a mut String) -> ReadLineFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn lines(self) -> Lines<Self> where
Self: Unpin,
[src]
Self: Unpin,
fn split(self, byte: u8) -> Split<Self>
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ReadExt for T where
T: AsyncRead + ?Sized,
[src]
T: AsyncRead + ?Sized,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn take(self, limit: u64) -> Take<Self>
[src]
fn by_ref(&mut self) -> &mut Self
[src]
fn bytes(self) -> Bytes<Self>
[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
[src]
R: AsyncRead,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,