Struct reqwest_websocket::UpgradeResponse
source · pub struct UpgradeResponse { /* private fields */ }
Expand description
The server’s response to the websocket upgrade request.
This implements Deref<Target = Response>
, so you can access all the usual
information from the Response
.
Implementations§
source§impl UpgradeResponse
impl UpgradeResponse
sourcepub async fn into_websocket(self) -> Result<WebSocket, Error>
pub async fn into_websocket(self) -> Result<WebSocket, Error>
Turns the response into a websocket. This checks if the websocket handshake was successful.
Methods from Deref<Target = Response>§
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get the StatusCode
of this Response
.
sourcepub fn content_length(&self) -> Option<u64>
pub fn content_length(&self) -> Option<u64>
Get the content-length of this response, if known.
Reasons it may not be known:
- The server didn’t send a
content-length
header. - The response is compressed and automatically decoded (thus changing the actual decoded length).
sourcepub fn remote_addr(&self) -> Option<SocketAddr>
pub fn remote_addr(&self) -> Option<SocketAddr>
Get the remote address used to get this Response
.
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
sourcepub fn error_for_status_ref(&self) -> Result<&Response, Error>
pub fn error_for_status_ref(&self) -> Result<&Response, Error>
Turn a reference to a response into an error if the server returned an error.
§Example
fn on_response(res: &Response) {
match res.error_for_status_ref() {
Ok(_res) => (),
Err(err) => {
// asserting a 400 as an example
// it could be any status between 400...599
assert_eq!(
err.status(),
Some(reqwest::StatusCode::BAD_REQUEST)
);
}
}
}
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for UpgradeResponse
impl Send for UpgradeResponse
impl Sync for UpgradeResponse
impl Unpin for UpgradeResponse
impl !UnwindSafe for UpgradeResponse
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