pub struct UpgradeResponse { /* private fields */ }
Expand description
The server’s response to the WebSocket
upgrade request.
On non-wasm platforms, this implements Deref<Target = Response>
, so you
can access all the usual information from the reqwest::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.
Sourcepub fn into_inner(self) -> Response
pub fn into_inner(self) -> Response
Consumes the response and returns the inner reqwest::Response
.
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 the response, if it is known.
This value does not directly represents the value of the Content-Length
header, but rather the size of the response’s body. To read the header’s
value, please use the Response::headers
method instead.
Reasons it may not be known:
- The response does not include a body (e.g. it responds to a
HEAD
request). - The response is gzipped 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)
);
}
}
}