Struct viceroy_lib::session::Session
source · pub struct Session { /* private fields */ }
Expand description
Data specific to an individual request, including any host-side allocations on behalf of the guest processing the request.
Implementations§
source§impl Session
impl Session
sourcepub fn new(
req_id: u64,
req: Request<Body>,
resp_sender: Sender<Response<Body>>,
client_ip: IpAddr,
backends: Arc<Backends>,
device_detection: Arc<DeviceDetection>,
geolocation: Arc<Geolocation>,
tls_config: TlsConfig,
dictionaries: Arc<Dictionaries>,
config_path: Arc<Option<PathBuf>>,
object_store: Arc<ObjectStores>,
secret_stores: Arc<SecretStores>
) -> Session
pub fn new( req_id: u64, req: Request<Body>, resp_sender: Sender<Response<Body>>, client_ip: IpAddr, backends: Arc<Backends>, device_detection: Arc<DeviceDetection>, geolocation: Arc<Geolocation>, tls_config: TlsConfig, dictionaries: Arc<Dictionaries>, config_path: Arc<Option<PathBuf>>, object_store: Arc<ObjectStores>, secret_stores: Arc<SecretStores> ) -> Session
Create an empty session.
sourcepub fn downstream_client_ip(&self) -> &IpAddr
pub fn downstream_client_ip(&self) -> &IpAddr
Retrieve the downstream client IP address associated with this session.
sourcepub fn downstream_request(&self) -> RequestHandle
pub fn downstream_request(&self) -> RequestHandle
Retrieve the handle corresponding to the downstream request.
sourcepub fn downstream_request_body(&self) -> BodyHandle
pub fn downstream_request_body(&self) -> BodyHandle
Retrieve the handle corresponding to the downstream request body.
sourcepub fn downstream_original_headers(&self) -> &HeaderMap
pub fn downstream_original_headers(&self) -> &HeaderMap
Access the header map that was copied from the original downstream request.
sourcepub fn send_downstream_response(
&mut self,
resp: Response<Body>
) -> Result<(), Error>
pub fn send_downstream_response( &mut self, resp: Response<Body> ) -> Result<(), Error>
Send the downstream response.
Yield an error if a response has already been sent.
§Panics
This method must only be called once, after a channel has been opened with
Session::set_downstream_response_sender
, and before the associated
oneshot::Receiver has been dropped.
This method will panic if:
- the downstream response channel was never opened
- the associated receiver was dropped prematurely
sourcepub fn close_downstream_response_sender(&mut self)
pub fn close_downstream_response_sender(&mut self)
Close the downstream response sender, potentially without sending any response.
sourcepub fn insert_body(&mut self, body: Body) -> BodyHandle
pub fn insert_body(&mut self, body: Body) -> BodyHandle
Insert a Body
into the session.
This method returns the BodyHandle
, which can then be used to access and mutate
the response parts.
sourcepub fn body(&self, handle: BodyHandle) -> Result<&Body, HandleError>
pub fn body(&self, handle: BodyHandle) -> Result<&Body, HandleError>
Get a reference to a Body
, given its BodyHandle
.
Returns a HandleError
if the handle is not associated with a body in the session.
sourcepub fn body_mut(&mut self, handle: BodyHandle) -> Result<&mut Body, HandleError>
pub fn body_mut(&mut self, handle: BodyHandle) -> Result<&mut Body, HandleError>
Get a mutable reference to a Body
, given its BodyHandle
.
Returns a HandleError
if the handle is not associated with a body in the session.
sourcepub fn take_body(&mut self, handle: BodyHandle) -> Result<Body, HandleError>
pub fn take_body(&mut self, handle: BodyHandle) -> Result<Body, HandleError>
Take ownership of a Body
, given its BodyHandle
.
Returns a HandleError
if the handle is not associated with a body in the session.
sourcepub fn drop_body(&mut self, handle: BodyHandle) -> Result<(), HandleError>
pub fn drop_body(&mut self, handle: BodyHandle) -> Result<(), HandleError>
Drop a Body
from the Session
, given its [BodyHandle
][crate::wiggle_abi::types::BodyHandle].
Returns a HandleError
if the handle is not associated with a body in the session.
sourcepub fn begin_streaming(
&mut self,
handle: BodyHandle
) -> Result<Body, HandleError>
pub fn begin_streaming( &mut self, handle: BodyHandle ) -> Result<Body, HandleError>
Transition a normal Body
into the write end of a streaming body, returning
the original body with the read end appended.
Returns a HandleError
if the handle is not associated with a body in the session.
sourcepub fn is_streaming_body(&self, handle: BodyHandle) -> bool
pub fn is_streaming_body(&self, handle: BodyHandle) -> bool
Returns true
if and only if the provided BodyHandle
is the downstream body being sent.
To get a mutable reference to the streaming body Sender
, see
Session::streaming_body_mut
.
sourcepub fn streaming_body_mut(
&mut self,
handle: BodyHandle
) -> Result<&mut StreamingBody, HandleError>
pub fn streaming_body_mut( &mut self, handle: BodyHandle ) -> Result<&mut StreamingBody, HandleError>
Get a mutable reference to the streaming body Sender
, if and only if the provided
BodyHandle
is the downstream body being sent.
To check if a handle is the currently-streaming downstream response body, see
Session::is_streaming_body
.
Returns a HandleError
if the handle is not associated with a body in the session.
sourcepub fn take_streaming_body(
&mut self,
handle: BodyHandle
) -> Result<StreamingBody, HandleError>
pub fn take_streaming_body( &mut self, handle: BodyHandle ) -> Result<StreamingBody, HandleError>
Take ownership of a streaming body Sender
, if and only if the provided
BodyHandle
is the downstream body being sent.
To check if a handle is the currently-streaming downstream response body, see
Session::is_streaming_body
.
Returns a HandleError
if the handle is not associated with a body in the session.
sourcepub fn insert_request_parts(&mut self, parts: Parts) -> RequestHandle
pub fn insert_request_parts(&mut self, parts: Parts) -> RequestHandle
Insert the Parts
of a Request
into the session.
This method returns a new RequestHandle
, which can then be used to access
and mutate the request parts.
sourcepub fn request_parts(
&self,
handle: RequestHandle
) -> Result<&Parts, HandleError>
pub fn request_parts( &self, handle: RequestHandle ) -> Result<&Parts, HandleError>
Get a reference to the Parts
of a Request
, given its
RequestHandle
.
Returns a HandleError
if the handle is not associated with a request in the
session.
sourcepub fn request_parts_mut(
&mut self,
handle: RequestHandle
) -> Result<&mut Parts, HandleError>
pub fn request_parts_mut( &mut self, handle: RequestHandle ) -> Result<&mut Parts, HandleError>
Get a mutable reference to the Parts
of a Request
, given its
RequestHandle
.
Returns a HandleError
if the handle is not associated with a request in the
session.
sourcepub fn take_request_parts(
&mut self,
handle: RequestHandle
) -> Result<Parts, HandleError>
pub fn take_request_parts( &mut self, handle: RequestHandle ) -> Result<Parts, HandleError>
Take ownership of the Parts
of a Request
, given its
RequestHandle
.
Returns a HandleError
if the handle is not associated with a request in the
session.
sourcepub fn insert_response_parts(&mut self, parts: Parts) -> ResponseHandle
pub fn insert_response_parts(&mut self, parts: Parts) -> ResponseHandle
Insert the Parts
of a Response
into the session.
This method returns a new ResponseHandle
, which can then be used to access
and mutate the response parts.
sourcepub fn response_parts(
&self,
handle: ResponseHandle
) -> Result<&Parts, HandleError>
pub fn response_parts( &self, handle: ResponseHandle ) -> Result<&Parts, HandleError>
Get a reference to the Parts
of a Response
, given its
ResponseHandle
.
Returns a HandleError
if the handle is not associated with a response in the
session.
sourcepub fn response_parts_mut(
&mut self,
handle: ResponseHandle
) -> Result<&mut Parts, HandleError>
pub fn response_parts_mut( &mut self, handle: ResponseHandle ) -> Result<&mut Parts, HandleError>
Get a mutable reference to the Parts
of a Response
, given its
ResponseHandle
.
Returns a HandleError
if the handle is not associated with a response in the
session.
sourcepub fn take_response_parts(
&mut self,
handle: ResponseHandle
) -> Result<Parts, HandleError>
pub fn take_response_parts( &mut self, handle: ResponseHandle ) -> Result<Parts, HandleError>
Take ownership of the Parts
of a Response
, given its
ResponseHandle
.
Returns a HandleError
if the handle is not associated with a response in the
session.
pub fn insert_response( &mut self, resp: Response<Body> ) -> (ResponseHandle, BodyHandle)
sourcepub fn log_endpoint_handle(&mut self, name: &[u8]) -> EndpointHandle
pub fn log_endpoint_handle(&mut self, name: &[u8]) -> EndpointHandle
Get an EndpointHandle
from the session, corresponding to the provided
endpoint name. A new backing LogEndpoint
will be created if one does not
already exist.
sourcepub fn log_endpoint(
&self,
handle: EndpointHandle
) -> Result<&LogEndpoint, HandleError>
pub fn log_endpoint( &self, handle: EndpointHandle ) -> Result<&LogEndpoint, HandleError>
Get a reference to a LogEndpoint
, given its EndpointHandle
.
Returns a HandleError
if the handle is not associated with an endpoint in the
session.
sourcepub fn dynamic_backend(&self, name: &str) -> Option<&Arc<Backend>>
pub fn dynamic_backend(&self, name: &str) -> Option<&Arc<Backend>>
Look up a dynamic backend (only) by name.
sourcepub fn backend_names(&self) -> impl Iterator<Item = &String>
pub fn backend_names(&self) -> impl Iterator<Item = &String>
Return the full list of static and dynamic backend names as an Iterator
.
sourcepub fn add_backend(&mut self, name: &str, info: Backend) -> bool
pub fn add_backend(&mut self, name: &str, info: Backend) -> bool
Try to add a backend with the given name prefix to our set of current backends. Upon success, return true. If the name already exists somewhere, return false; the caller should signal an appropriate error.
sourcepub fn tls_config(&self) -> &TlsConfig
pub fn tls_config(&self) -> &TlsConfig
Access the TLS configuration.
pub fn device_detection_lookup(&self, user_agent: &str) -> Option<String>
sourcepub fn dictionary_handle(
&mut self,
name: &str
) -> Result<DictionaryHandle, Error>
pub fn dictionary_handle( &mut self, name: &str ) -> Result<DictionaryHandle, Error>
Look up a dictionary-handle by name.
sourcepub fn dictionary(
&self,
handle: DictionaryHandle
) -> Result<&Dictionary, HandleError>
pub fn dictionary( &self, handle: DictionaryHandle ) -> Result<&Dictionary, HandleError>
Look up a dictionary by dictionary-handle.
sourcepub fn dictionaries(&self) -> &Arc<Dictionaries>
pub fn dictionaries(&self) -> &Arc<Dictionaries>
Access the dictionary map.
pub fn geolocation_lookup(&self, addr: &IpAddr) -> Option<String>
pub fn obj_store_handle( &mut self, key: &str ) -> Result<ObjectStoreHandle, Error>
pub fn get_obj_store_key( &self, handle: ObjectStoreHandle ) -> Option<&ObjectStoreKey>
pub fn obj_insert( &self, obj_store_key: ObjectStoreKey, obj_key: ObjectKey, obj: Vec<u8> ) -> Result<(), ObjectStoreError>
sourcepub fn insert_pending_kv_insert(
&mut self,
pending: PendingKvInsertTask
) -> PendingKvInsertHandle
pub fn insert_pending_kv_insert( &mut self, pending: PendingKvInsertTask ) -> PendingKvInsertHandle
Insert a [PendingKvInsert
] into the session.
This method returns a new [PendingKvInsertHandle
], which can then be used to access
and mutate the pending insert.
sourcepub fn take_pending_kv_insert(
&mut self,
handle: PendingKvInsertHandle
) -> Result<PendingKvInsertTask, HandleError>
pub fn take_pending_kv_insert( &mut self, handle: PendingKvInsertHandle ) -> Result<PendingKvInsertTask, HandleError>
Take ownership of a [PendingKvInsert
], given its [PendingKvInsertHandle
].
Returns a HandleError
if the handle is not associated with a pending insert in the
session.
sourcepub fn pending_kv_insert(
&self,
handle: PendingKvInsertHandle
) -> Result<&PendingKvInsertTask, HandleError>
pub fn pending_kv_insert( &self, handle: PendingKvInsertHandle ) -> Result<&PendingKvInsertTask, HandleError>
Get a reference to a [PendingInsert
], given its [PendingKvInsertHandle
].
Returns a HandleError
if the handle is not associated with a insert in the
session.
pub fn obj_delete( &self, obj_store_key: ObjectStoreKey, obj_key: ObjectKey ) -> Result<(), ObjectStoreError>
sourcepub fn insert_pending_kv_delete(
&mut self,
pending: PendingKvDeleteTask
) -> PendingKvDeleteHandle
pub fn insert_pending_kv_delete( &mut self, pending: PendingKvDeleteTask ) -> PendingKvDeleteHandle
Insert a [PendingKvDelete
] into the session.
This method returns a new [PendingKvDeleteHandle
], which can then be used to access
and mutate the pending delete.
sourcepub fn take_pending_kv_delete(
&mut self,
handle: PendingKvDeleteHandle
) -> Result<PendingKvDeleteTask, HandleError>
pub fn take_pending_kv_delete( &mut self, handle: PendingKvDeleteHandle ) -> Result<PendingKvDeleteTask, HandleError>
Take ownership of a [PendingKvDelete
], given its [PendingKvDeleteHandle
].
Returns a HandleError
if the handle is not associated with a pending delete in the
session.
sourcepub fn pending_kv_delete(
&self,
handle: PendingKvDeleteHandle
) -> Result<&PendingKvDeleteTask, HandleError>
pub fn pending_kv_delete( &self, handle: PendingKvDeleteHandle ) -> Result<&PendingKvDeleteTask, HandleError>
Get a reference to a [PendingDelete
], given its [PendingKvDeleteHandle
].
Returns a HandleError
if the handle is not associated with a delete in the
session.
pub fn obj_lookup( &self, obj_store_key: &ObjectStoreKey, obj_key: &ObjectKey ) -> Result<Vec<u8>, ObjectStoreError>
sourcepub fn insert_pending_kv_lookup(
&mut self,
pending: PendingKvLookupTask
) -> PendingKvLookupHandle
pub fn insert_pending_kv_lookup( &mut self, pending: PendingKvLookupTask ) -> PendingKvLookupHandle
Insert a [PendingLookup
] into the session.
This method returns a new [PendingKvLookupHandle
], which can then be used to access
and mutate the pending lookup.
sourcepub fn take_pending_kv_lookup(
&mut self,
handle: PendingKvLookupHandle
) -> Result<PendingKvLookupTask, HandleError>
pub fn take_pending_kv_lookup( &mut self, handle: PendingKvLookupHandle ) -> Result<PendingKvLookupTask, HandleError>
Take ownership of a [PendingLookup
], given its [PendingKvLookupHandle
].
Returns a HandleError
if the handle is not associated with a pending lookup in the
session.
sourcepub fn pending_kv_lookup(
&self,
handle: PendingKvLookupHandle
) -> Result<&PendingKvLookupTask, HandleError>
pub fn pending_kv_lookup( &self, handle: PendingKvLookupHandle ) -> Result<&PendingKvLookupTask, HandleError>
Get a reference to a [PendingLookup
], given its [PendingKvLookupHandle
].
Returns a HandleError
if the handle is not associated with a lookup in the
session.
pub fn secret_store_handle(&mut self, name: &str) -> Option<SecretStoreHandle>
pub fn secret_store_name(&self, handle: SecretStoreHandle) -> Option<String>
pub fn secret_handle( &mut self, store_name: &str, secret_name: &str ) -> Option<SecretHandle>
pub fn secret_lookup(&self, handle: SecretHandle) -> Option<SecretLookup>
pub fn add_secret(&mut self, plaintext: Vec<u8>) -> SecretHandle
pub fn secret_stores(&self) -> &Arc<SecretStores>
sourcepub fn insert_pending_request(
&mut self,
pending: PeekableTask<Response<Body>>
) -> PendingRequestHandle
pub fn insert_pending_request( &mut self, pending: PeekableTask<Response<Body>> ) -> PendingRequestHandle
Insert a [PendingRequest
] into the session.
This method returns a new [PendingRequestHandle
], which can then be used to access
and mutate the pending request.
sourcepub fn pending_request(
&self,
handle: PendingRequestHandle
) -> Result<&PeekableTask<Response<Body>>, HandleError>
pub fn pending_request( &self, handle: PendingRequestHandle ) -> Result<&PeekableTask<Response<Body>>, HandleError>
Get a reference to a [PendingRequest
], given its [PendingRequestHandle
].
Returns a HandleError
if the handle is not associated with a request in the
session.
sourcepub fn pending_request_mut(
&mut self,
handle: PendingRequestHandle
) -> Result<&mut PeekableTask<Response<Body>>, HandleError>
pub fn pending_request_mut( &mut self, handle: PendingRequestHandle ) -> Result<&mut PeekableTask<Response<Body>>, HandleError>
Get a mutable reference to a [PendingRequest
], given its [PendingRequestHandle
].
Returns a HandleError
if the handle is not associated with a request in the
session.
sourcepub fn take_pending_request(
&mut self,
handle: PendingRequestHandle
) -> Result<PeekableTask<Response<Body>>, HandleError>
pub fn take_pending_request( &mut self, handle: PendingRequestHandle ) -> Result<PeekableTask<Response<Body>>, HandleError>
Take ownership of a [PendingRequest
], given its [PendingRequestHandle
].
Returns a HandleError
if the handle is not associated with a pending request in the
session.
pub fn reinsert_pending_request( &mut self, handle: PendingRequestHandle, pending_req: PeekableTask<Response<Body>> ) -> Result<(), HandleError>
sourcepub fn prepare_select_targets(
&mut self,
handles: impl IntoIterator<Item = AsyncItemHandle>
) -> Result<Vec<SelectTarget>, HandleError>
pub fn prepare_select_targets( &mut self, handles: impl IntoIterator<Item = AsyncItemHandle> ) -> Result<Vec<SelectTarget>, HandleError>
Take ownership of multiple [PendingRequest
]s in preparation for a select
.
Returns a HandleError
if any of the handles are not associated with a pending
request in the session.
sourcepub fn reinsert_select_targets(&mut self, targets: Vec<SelectTarget>)
pub fn reinsert_select_targets(&mut self, targets: Vec<SelectTarget>)
Put the given vector of select
targets back into the pending request table, using the handles
stored within each [SelectTarget
].
sourcepub fn req_id(&self) -> u64
pub fn req_id(&self) -> u64
Returns the unique identifier for the request this session is processing.
sourcepub fn config_path(&self) -> &Arc<Option<PathBuf>>
pub fn config_path(&self) -> &Arc<Option<PathBuf>>
Access the path to the configuration file for this invocation.
pub fn async_item_mut( &mut self, handle: AsyncItemHandle ) -> Result<&mut AsyncItem, HandleError>
pub fn take_async_item( &mut self, handle: AsyncItemHandle ) -> Result<AsyncItem, HandleError>
pub async fn select_impl( &mut self, handles: impl IntoIterator<Item = AsyncItemHandle> ) -> Result<usize, Error>
Auto Trait Implementations§
impl Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self
file descriptor. Read more