pub struct Context<C> { /* private fields */ }Expand description
A request being crawled, with everything needed to handle it.
It holds the Request, a client to fetch it with, a Queue to add
the links it leads to, and the crawl’s datasets. Handlers borrow it, so
several of them can handle one request: the request is fetched once, by
the first response or body, and the
response’s head is kept. The body is always read from the client, so a
browser page reads as currently rendered.
Implementations§
Source§impl<C> Context<C>
impl<C> Context<C>
Sourcepub fn new(request: Request, client: C) -> Self
pub fn new(request: Request, client: C) -> Self
Creates a standalone context, e.g. to test a handler.
It gets an empty queue of its own and no datasets; see
with_queue and
with_dataset.
Sourcepub fn with_queue(self, queue: &Queue) -> Self
pub fn with_queue(self, queue: &Queue) -> Self
Replaces the queue, binding it to the request.
Sourcepub fn with_dataset<T, D>(self, dataset: D) -> Self
pub fn with_dataset<T, D>(self, dataset: D) -> Self
Registers dataset for items of type T.
Sourcepub const fn request_mut(&mut self) -> &mut Request
pub const fn request_mut(&mut self) -> &mut Request
Returns the request mutably, e.g. to add headers before fetching.
Sourcepub async fn response(&self) -> Result<&Response<()>>where
C: Client,
pub async fn response(&self) -> Result<&Response<()>>where
C: Client,
Returns the response’s head, fetching the request on the first call.
Later calls return the same head without fetching again. A failed fetch is not kept: the next call tries again. Once fetched, links followed through the queue, including clones taken earlier, resolve against the URI the response was served from.
§Errors
Returns an error if the client fails to fetch the request.