pub struct FullstackContext { /* private fields */ }Expand description
The context provided by dioxus fullstack for server-side rendering.
This context will only be set on the server during the initial streaming response and inside server functions.
Implementations§
Source§impl FullstackContext
impl FullstackContext
Sourcepub fn new(parts: Parts) -> FullstackContext
pub fn new(parts: Parts) -> FullstackContext
Create a new streaming context. You should not need to call this directly. Dioxus fullstack will provide this context for you.
Sourcepub fn commit_initial_chunk(&mut self)
pub fn commit_initial_chunk(&mut self)
Commit the initial chunk of the response. This will be called automatically if you are using the dioxus router when the suspense boundary above the router is resolved. Otherwise, you will need to call this manually to start the streaming part of the response.
Once this method has been called, the http response parts can no longer be modified.
Sourcepub fn streaming_state(&self) -> StreamingStatus
pub fn streaming_state(&self) -> StreamingStatus
Get the current status of the streaming response. This method is reactive and will cause the current reactive context to rerun when the status changes.
Sourcepub fn parts_mut(&self) -> RwLockWriteGuard<'_, RawRwLock, Parts>
pub fn parts_mut(&self) -> RwLockWriteGuard<'_, RawRwLock, Parts>
Access the http request parts mutably. This will allow you to modify headers and other parts of the request.
Sourcepub async fn scope<F, R>(self, fut: F) -> Rwhere
F: Future<Output = R>,
pub async fn scope<F, R>(self, fut: F) -> Rwhere
F: Future<Output = R>,
Run a future within the scope of this FullstackContext.
Sourcepub async fn extract<T, M>() -> Result<T, ServerFnError>where
T: FromRequest<FullstackContext, M>,
pub async fn extract<T, M>() -> Result<T, ServerFnError>where
T: FromRequest<FullstackContext, M>,
Extract an axum extractor from the current request.
The body of the request is always empty when using this method, as the body can only be consumed once in the server function extractors.
Sourcepub fn current() -> Option<FullstackContext>
pub fn current() -> Option<FullstackContext>
Get the current FullstackContext if it exists. This will return None if called on the client
or outside of a streaming response on the server or server function.
Sourcepub fn current_http_status(&self) -> HttpError
pub fn current_http_status(&self) -> HttpError
Get the current HTTP status for the route. This will default to 200 OK, but can be modified
by calling FullstackContext::commit_error_status with an error.
pub fn set_current_http_status(&mut self, status: HttpError)
Sourcepub fn add_response_header(
&self,
key: impl Into<HeaderName>,
value: impl Into<HeaderValue>,
)
pub fn add_response_header( &self, key: impl Into<HeaderName>, value: impl Into<HeaderValue>, )
Add a header to the response. This will be sent to the client when the response is committed.
Sourcepub fn take_response_headers(&self) -> Option<HeaderMap>
pub fn take_response_headers(&self) -> Option<HeaderMap>
Take the response headers out of the context. This will leave the context without any headers, so it should only be called once when the response is being committed.
Sourcepub fn commit_http_status(status: StatusCode, message: Option<String>)
pub fn commit_http_status(status: StatusCode, message: Option<String>)
Set the current HTTP status for the route. This will be used when committing the response to the client.
Sourcepub fn commit_error_status(error: impl Into<CapturedError>) -> HttpError
pub fn commit_error_status(error: impl Into<CapturedError>) -> HttpError
Commit the CapturedError as the current HTTP status for the route.
This will attempt to downcast the error to known types and set the appropriate
status code. If the error type is unknown, it will default to
StatusCode::INTERNAL_SERVER_ERROR.
Trait Implementations§
Source§impl Clone for FullstackContext
impl Clone for FullstackContext
Source§fn clone(&self) -> FullstackContext
fn clone(&self) -> FullstackContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more