pub struct StubHttpClient { /* private fields */ }Expand description
Re-export framework services (HTTP, URI, etc.) from the dedicated services crate. An HTTP client that answers from a function rather than a network.
A screen driven from a recorded payload, a robot run that must not depend on a server, a test that wants a specific failure: all of them want one thing, which is to decide what a request answers. Written as a client each time, that is the same dozen lines of body plumbing repeated — and each copy is a chance to answer differently from the real client.
ⓘ
let client: HttpClientRef = Arc::new(StubHttpClient::from_text(move |url| {
Ok(fixture_for(url))
}));Implementations§
Source§impl StubHttpClient
impl StubHttpClient
Sourcepub fn new(
answer: impl Fn(&HttpRequest) -> Result<HttpResponse, HttpError> + Send + Sync + 'static,
) -> StubHttpClient
pub fn new( answer: impl Fn(&HttpRequest) -> Result<HttpResponse, HttpError> + Send + Sync + 'static, ) -> StubHttpClient
Answers from a function of the whole request.
Trait Implementations§
Source§impl HttpClient for StubHttpClient
impl HttpClient for StubHttpClient
Source§fn send<'a>(
&'a self,
request: &'a HttpRequest,
_control: HttpControl,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'a>>
fn send<'a>( &'a self, request: &'a HttpRequest, _control: HttpControl, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'a>>
Sends
request, resolving when the response’s status line has arrived
and its body is ready to be read.Source§fn get_text<'a>(
&'a self,
url: &'a str,
) -> Pin<Box<dyn Future<Output = Result<String, HttpError>> + Send + 'a>>
fn get_text<'a>( &'a self, url: &'a str, ) -> Pin<Box<dyn Future<Output = Result<String, HttpError>> + Send + 'a>>
The body of a successful
GET, as text.Source§fn get_bytes<'a>(
&'a self,
url: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HttpError>> + Send + 'a>>
fn get_bytes<'a>( &'a self, url: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HttpError>> + Send + 'a>>
The body of a successful
GET.Source§fn download_to<'a>(
&'a self,
url: &'a str,
target: &'a Path,
control: HttpControl,
) -> Pin<Box<dyn Future<Output = Result<u64, HttpError>> + Send + 'a>>
fn download_to<'a>( &'a self, url: &'a str, target: &'a Path, control: HttpControl, ) -> Pin<Box<dyn Future<Output = Result<u64, HttpError>> + Send + 'a>>
Streams a response into
target, resuming from its current length when
the server supports byte ranges, and returns the file’s whole length. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for StubHttpClient
impl !UnwindSafe for StubHttpClient
impl Freeze for StubHttpClient
impl Send for StubHttpClient
impl Sync for StubHttpClient
impl Unpin for StubHttpClient
impl UnsafeUnpin for StubHttpClient
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.