Struct HttpConnection

Source
pub struct HttpConnection<T> { /* private fields */ }
Expand description

A wrapper over a HTTP Connection.

Implementations§

Source§

impl<T: Read + Write + ScmSocket> HttpConnection<T>

Source

pub fn new(stream: T) -> Self

Creates an empty connection.

Source

pub fn set_payload_max_size(&mut self, request_payload_max_size: usize)

This function sets the limit for PUT/PATCH requests. It overwrites the default limit of 0.05MiB with the one allowed by server.

Source

pub fn try_read(&mut self) -> Result<(), ConnectionError>

Tries to read new bytes from the stream and automatically update the request. Meant to be used only with non-blocking streams and an EPOLL structure. Should be called whenever an EPOLLIN event is signaled.

§Errors

StreamError is returned when an IO operation fails. ConnectionClosed is returned when a client prematurely closes the connection. ParseError is returned when a parsing operation fails.

Source

pub fn try_write(&mut self) -> Result<(), ConnectionError>

Tries to write the first available response to the provided stream. Meant to be used only with non-blocking streams and an EPOLL structure. Should be called whenever an EPOLLOUT event is signaled. If no bytes were written to the stream or error occurred while trying to write to stream, we will discard all responses from response_queue because there is no way to deliver it to client.

§Errors

StreamError is returned when an IO operation fails. ConnectionClosed is returned when trying to write on a closed connection. InvalidWrite is returned when trying to write on a connection with an empty outgoing buffer.

Source

pub fn clear_write_buffer(&mut self)

Discards all pending writes from the connection.

Source

pub fn enqueue_response(&mut self, response: Response)

Send a response back to the source of a request.

Source

pub fn pop_parsed_request(&mut self) -> Option<Request>

Returns the first parsed request in the queue or None if the queue is empty.

Source

pub fn has_parsed_requests(&self) -> bool

Returns if parsed_requests is not empty

Source

pub fn pending_write(&self) -> bool

Returns true if there are bytes waiting to be written into the stream.

Trait Implementations§

Source§

impl<T> AsRawFd for HttpConnection<T>
where T: AsRawFd,

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more

Auto Trait Implementations§

§

impl<T> Freeze for HttpConnection<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for HttpConnection<T>
where T: RefUnwindSafe,

§

impl<T> Send for HttpConnection<T>
where T: Send,

§

impl<T> Sync for HttpConnection<T>
where T: Sync,

§

impl<T> Unpin for HttpConnection<T>
where T: Unpin,

§

impl<T> UnwindSafe for HttpConnection<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.