Struct pingora_proxy::Session

source ·
pub struct Session {
    pub downstream_session: Box<ServerSession>,
    pub cache: HttpCache,
    pub upstream_compression: ResponseCompressionCtx,
    pub downstream_compression: ResponseCompressionCtx,
    pub ignore_downstream_range: bool,
    /* private fields */
}
Expand description

The established HTTP session

This object is what users interact with in order to access the request itself or change the proxy behavior.

Fields§

§downstream_session: Box<ServerSession>

the HTTP session to downstream (the client)

§cache: HttpCache

The interface to control HTTP caching

§upstream_compression: ResponseCompressionCtx

(de)compress responses coming into the proxy (from upstream)

§downstream_compression: ResponseCompressionCtx

(de)compress responses leaving the proxy (to downstream)

§ignore_downstream_range: bool

ignore downstream range (skip downstream range filters)

Implementations§

source§

impl Session

source

pub fn new_h1(stream: Stream) -> Self

Create a new Session from the given Stream

This function is mostly used for testing and mocking.

source

pub fn as_downstream_mut(&mut self) -> &mut HttpSession

source

pub fn as_downstream(&self) -> &HttpSession

Methods from Deref<Target = HttpSession>§

source

pub fn is_http2(&self) -> bool

Whether the session is HTTP/2. If not it is HTTP/1.x

source

pub async fn read_request(&mut self) -> Result<bool, Box<Error>>

Read the request header. This method is required to be called first before doing anything else with the session.

  • Ok(true): successful
  • Ok(false): client exit without sending any bytes. This is normal on reused connection. In this case the user should give up this session.
source

pub fn req_header(&self) -> &RequestHeader

Return the request header it just read.

§Panic

This function will panic if Self::read_request() is not called.

source

pub fn req_header_mut(&mut self) -> &mut RequestHeader

Return a mutable reference to request header it just read.

§Panic

This function will panic if Self::read_request() is not called.

source

pub fn get_header<K>(&self, key: K) -> Option<&HeaderValue>
where K: AsHeaderName,

Return the header by name. None if the header doesn’t exist.

In case there are multiple headers under the same name, the first one will be returned. To get all the headers: use self.req_header().headers.get_all().

source

pub fn get_header_bytes<K>(&self, key: K) -> &[u8]
where K: AsHeaderName,

Get the header value in its raw format. If the header doesn’t exist, return an empty slice.

source

pub async fn read_request_body(&mut self) -> Result<Option<Bytes>, Box<Error>>

Read the request body. Ok(None) if no (more) body to read

source

pub async fn write_response_header( &mut self, resp: Box<ResponseHeader> ) -> Result<(), Box<Error>>

Write the response header to client Informational headers (status code 100-199, excluding 101) can be written multiple times the final response header (status code 200+ or 101) is written.

source

pub async fn write_response_header_ref( &mut self, resp: &ResponseHeader ) -> Result<(), Box<Error>>

Similar to write_response_header(), this fn will clone the resp internally

source

pub async fn write_response_body( &mut self, data: Bytes ) -> Result<(), Box<Error>>

Write the response body to client

source

pub async fn write_response_trailers( &mut self, trailers: HeaderMap ) -> Result<(), Box<Error>>

Write the response trailers to client

source

pub async fn response_duplex_vec( &mut self, tasks: Vec<HttpTask> ) -> Result<bool, Box<Error>>

source

pub fn set_keepalive(&mut self, duration: Option<u64>)

Set connection reuse. duration defines how long the connection is kept open for the next request to reuse. Noop for h2

source

pub fn request_summary(&self) -> String

Return a digest of the request including the method, path and Host header

source

pub fn response_written(&self) -> Option<&ResponseHeader>

Return the written response header. None if it is not written yet. Only the final (status code >= 200 or 101) response header will be returned

source

pub async fn shutdown(&mut self)

Give up the http session abruptly. For H1 this will close the underlying connection For H2 this will send RESET frame to end this stream without impacting the connection

source

pub fn to_h1_raw(&self) -> Bytes

source

pub fn is_body_done(&mut self) -> bool

Whether the whole request body is sent

source

pub async fn finish_body(&mut self) -> Result<(), Box<Error>>

Notify the client that the entire body is sent for H1 chunked encoding, this will end the last empty chunk for H1 content-length, this has no effect. for H2, this will send an empty DATA frame with END_STREAM flag

source

pub async fn respond_error(&mut self, error: u16)

Send error response to client

source

pub fn is_body_empty(&mut self) -> bool

Whether there is no request body

source

pub fn retry_buffer_truncated(&self) -> bool

source

pub fn enable_retry_buffering(&mut self)

source

pub fn get_retry_buffer(&self) -> Option<Bytes>

source

pub async fn read_body_or_idle( &mut self, no_body_expected: bool ) -> Result<Option<Bytes>, Box<Error>>

Read body (same as read_request_body()) or pending forever until downstream terminates the session.

source

pub fn as_http1(&self) -> Option<&HttpSession>

source

pub fn as_http2(&self) -> Option<&HttpSession>

source

pub async fn write_continue_response(&mut self) -> Result<(), Box<Error>>

Write a 100 Continue response to the client.

source

pub fn is_upgrade_req(&self) -> bool

Whether this request is for upgrade (e.g., websocket)

source

pub fn body_bytes_sent(&self) -> usize

Return how many response body bytes (application, not wire) already sent downstream

source

pub fn body_bytes_read(&self) -> usize

Return how many request body bytes (application, not wire) already read from downstream

source

pub fn digest(&self) -> Option<&Digest>

Return the digest for the session.

source

pub fn client_addr(&self) -> Option<&SocketAddr>

Return the client (peer) address of the connnection.

source

pub fn server_addr(&self) -> Option<&SocketAddr>

Return the server (local) address of the connection.

Trait Implementations§

source§

impl AsMut<Session> for Session

source§

fn as_mut(&mut self) -> &mut HttpSession

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Session> for Session

source§

fn as_ref(&self) -> &HttpSession

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Deref for Session

§

type Target = Session

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Session

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more