Struct ClientRequestBuilder
pub struct ClientRequestBuilder { /* private fields */ }Available on crate features
ws and handshake only.Expand description
Builder for a custom IntoClientRequest with options to add
custom additional headers and sub protocols.
§Example
use http::Uri;
use tungstenite::{connect, ClientRequestBuilder};
let uri: Uri = "ws://localhost:3012/socket".parse().unwrap();
let token = "my_jwt_token";
let builder = ClientRequestBuilder::new(uri)
.with_header("Authorization", format!("Bearer {token}"))
.with_sub_protocol("my_sub_protocol");
let socket = connect(builder).unwrap();Implementations§
§impl ClientRequestBuilder
impl ClientRequestBuilder
pub const fn new(uri: Uri) -> ClientRequestBuilder
pub const fn new(uri: Uri) -> ClientRequestBuilder
Initializes an empty request builder
pub fn with_header<K, V>(self, key: K, value: V) -> ClientRequestBuilder
pub fn with_header<K, V>(self, key: K, value: V) -> ClientRequestBuilder
Adds (key, value) as an additional header to the handshake request
pub fn with_sub_protocol<P>(self, protocol: P) -> ClientRequestBuilder
pub fn with_sub_protocol<P>(self, protocol: P) -> ClientRequestBuilder
Adds protocol to the handshake request subprotocols (Sec-WebSocket-Protocol)
Trait Implementations§
§impl Clone for ClientRequestBuilder
impl Clone for ClientRequestBuilder
§fn clone(&self) -> ClientRequestBuilder
fn clone(&self) -> ClientRequestBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more§impl Debug for ClientRequestBuilder
impl Debug for ClientRequestBuilder
§impl IntoClientRequest for ClientRequestBuilder
impl IntoClientRequest for ClientRequestBuilder
Auto Trait Implementations§
impl !Freeze for ClientRequestBuilder
impl RefUnwindSafe for ClientRequestBuilder
impl Send for ClientRequestBuilder
impl Sync for ClientRequestBuilder
impl Unpin for ClientRequestBuilder
impl UnwindSafe for ClientRequestBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>
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 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>
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