pub struct LocalServerBuilder { /* private fields */ }local-server only.Expand description
Builder for a server that binds on a random port on localhost and waits for
a GET HTTP request.
The server is spawned when calling LocalServerBuilder::spawn().
The query string of the URI where the end-user is redirected is available by
.awaiting the LocalServerRedirectHandle, in case it should receive
parameters.
The server is shutdown when LocalServerRedirectHandle is dropped. It can
also be shutdown manually with a LocalServerShutdownHandle obtained from
LocalServerRedirectHandle::shutdown_handle().
Implementations§
Source§impl LocalServerBuilder
impl LocalServerBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a LocalServerBuilder using the default settings.
Sourcepub fn ip_address(self, ip_address: LocalServerIpAddress) -> Self
pub fn ip_address(self, ip_address: LocalServerIpAddress) -> Self
Set the IP address that the server should to bind to.
Defaults to LocalServerIpAddress::LocalhostAny.
Sourcepub fn port_range(self, range: Range<u16>) -> Self
pub fn port_range(self, range: Range<u16>) -> Self
The default range of ports the server will try to bind to randomly.
Care should be taken not to bind to a port blocked by browsers.
Defaults to ports in the 20000..30000 range.
Sourcepub fn bind_tries(self, tries: u8) -> Self
pub fn bind_tries(self, tries: u8) -> Self
The number of times the server will try to bind to a random port on localhost.
Since random ports might already be taken, this setting allows to try to bind to several random ports before giving up.
Defaults to 10.
Sourcepub fn response(self, response: LocalServerResponse) -> Self
pub fn response(self, response: LocalServerResponse) -> Self
Set the content of the page that the end user will see when they a redirected to the server’s URI.
Defaults to a plain text page with a generic message.
Sourcepub async fn spawn(self) -> Result<(Url, LocalServerRedirectHandle), Error>
pub async fn spawn(self) -> Result<(Url, LocalServerRedirectHandle), Error>
Spawn the server.
Returns the Url where the server is listening, and a
LocalServerRedirectHandle to await the redirect or to shutdown
the server. Returns an error if the server could not be bound to a port
on localhost.
Trait Implementations§
Source§impl Clone for LocalServerBuilder
impl Clone for LocalServerBuilder
Source§fn clone(&self) -> LocalServerBuilder
fn clone(&self) -> LocalServerBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LocalServerBuilder
impl Debug for LocalServerBuilder
Source§impl Default for LocalServerBuilder
impl Default for LocalServerBuilder
Source§fn default() -> LocalServerBuilder
fn default() -> LocalServerBuilder
Auto Trait Implementations§
impl Freeze for LocalServerBuilder
impl RefUnwindSafe for LocalServerBuilder
impl Send for LocalServerBuilder
impl Sync for LocalServerBuilder
impl Unpin for LocalServerBuilder
impl UnwindSafe for LocalServerBuilder
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
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>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn 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>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which 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)
&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)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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