Skip to main content

RequestContext

Struct RequestContext 

Source
pub struct RequestContext { /* private fields */ }
Expand description

Metadata of one invocation.

The value is immutable and cheap to clone. Its Debug output contains header names but no header values and no token.

Implementations§

Source§

impl RequestContext

Source

pub fn builder(session_id: impl Into<String>) -> RequestContextBuilder

Starts a context for the session session_id.

The runtime server builds the context of each invocation itself. Use this builder in tests, or to run code that reads the ambient context outside the server.

Source

pub fn session_id(&self) -> &str

The runtime session ID. It comes from the X-Amzn-Bedrock-AgentCore-Runtime-Session-Id header, or from the top-level sessionId string of the request body when the header is absent.

Source

pub fn request_id(&self) -> &str

The request ID. It comes from the X-Amzn-Bedrock-AgentCore-Runtime-Request-Id header. The SDK generates a UUID when the header is absent.

In tests against AgentCore Runtime the service did not send this header, so the ID of a deployed agent is the generated UUID. It is not the request ID that the caller of InvokeAgentRuntime receives. To find the log lines of a call, search for the session ID.

Source

pub fn workload_access_token(&self) -> Option<&WorkloadAccessToken>

The workload access token that AgentCore Runtime sent with this invocation.

It comes from the X-Amz-Bedrock-AgentCore-Identity-WAT header, or from the WorkloadAccessToken header when the first one is absent.

Source

pub fn oauth2_callback_url(&self) -> Option<&str>

The OAuth2 callback URL from the OAuth2CallbackUrl header.

AgentCore Runtime does not add this header. In tests against the service it passed the header on only when the caller sent it and the request header allowlist of the agent runtime named it. An agent that needs a callback URL on AgentCore Runtime sets it on the request, with Oauth2TokenBuilder::callback_url.

Source

pub fn headers(&self) -> &HeaderMap

The request headers that an agent may forward to other services.

The map holds only Authorization, headers whose name starts with X-Amzn-Bedrock-AgentCore-Runtime-Custom-, and X-Amz-Bedrock-AgentCore-Identity-WAT. A header that the request repeats has one entry, with the values joined by a comma and a space. Every value is marked sensitive, so Debug output of the map does not show it.

Source

pub fn request_headers(&self) -> &HeaderMap

The headers of the request as the server received them. They include the headers that the requestHeaderAllowlist of the agent runtime lets through, such as an X-Api-Key header, and the Accept header.

The encrypted workload identity context is not in the map. A header that the request repeats has one entry for each value. Every value is marked sensitive, so Debug output of the map does not show it. Forward only the headers of headers to other services.

Source§

impl RequestContext

Source

pub fn tasks(&self) -> &AsyncTasks

The registry of background work of the app that received this invocation. Work tracked here makes the app report HealthyBusy. See crate::tasks.

Trait Implementations§

Source§

impl Clone for RequestContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RequestContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Send + Sync> FromRequestParts<S> for RequestContext

On a route added with Builder::routes, a handler can take the request context as an argument.

The context is built from the request headers only, so the session ID must be in its header: a route that takes this argument replies 400 without it. The context’s tasks is the registry of the app.

On any other route the extraction fails with 500, because the route has no app whose registry the context could use.

Source§

type Rejection = Response<Body>

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

async fn from_request_parts( parts: &mut Parts, _state: &S, ) -> Result<Self, Self::Rejection>

Perform the extraction.

Auto Trait Implementations§

§

impl Forget for RequestContext

§

impl Freeze for RequestContext
where *const ArcInner<Inner> is !null: Freeze, PhantomData<ArcInner<Inner>>: Freeze,

§

impl Move for RequestContext

§

impl RefUnwindSafe for RequestContext

§

impl Send for RequestContext
where Arc<Inner>: Send,

§

impl Sync for RequestContext
where Arc<Inner>: Sync,

§

impl Unpin for RequestContext
where Arc<Inner>: Unpin,

§

impl UnsafeUnpin for RequestContext
where *const ArcInner<Inner> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner>>: UnsafeUnpin,

§

impl UnwindSafe for RequestContext
where Arc<Inner>: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<S, T> FromRequest<S, ViaParts> for T
where S: Send + Sync, T: FromRequestParts<S>,

Source§

type Rejection = <T as FromRequestParts<S>>::Rejection

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>

Perform the extraction.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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