pub struct WebSocketUpgradeError {
pub kind: ErrorKind,
/* private fields */
}websockets only.Expand description
An attempted upgrade to a WebSocket failed.
You can transform this back into the Conn with From::from/Into::into, if you need to
look at the server response.
Fields§
§kind: ErrorKindThe kind of error that occurred
Methods from Deref<Target = Conn>§
Sourcepub fn transport(&self) -> Option<&dyn Transport>
pub fn transport(&self) -> Option<&dyn Transport>
Borrows the transport for this conn
This should only be used to call your own custom methods on the transport that do not read or write any data. Calling any method that reads from or writes to the transport will disrupt the HTTP protocol.
Sourcepub fn transport_mut(&mut self) -> Option<&mut dyn Transport>
pub fn transport_mut(&mut self) -> Option<&mut dyn Transport>
Mutably borrow the transport for this conn
This should only be used to call your own custom methods on the transport that do not read or write any data. Calling any method that reads from or writes to the transport will disrupt the HTTP protocol.
Sourcepub fn url(&self) -> &Url
pub fn url(&self) -> &Url
Borrows the url for this conn.
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::from(client_config());
let conn = client.get("http://localhost:9080");
let url = conn.url(); //<-
assert_eq!(url.host_str().unwrap(), "localhost");Sourcepub fn url_mut(&mut self) -> &mut Url
pub fn url_mut(&mut self) -> &mut Url
Mutably borrow the url for this conn.
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::from(client_config());
let conn = client.get("http://localhost:9080");
let url = conn.url(); //<-
assert_eq!(url.host_str().unwrap(), "localhost");Sourcepub fn set_url(&mut self, url: Url) -> &mut Self
pub fn set_url(&mut self, url: Url) -> &mut Self
Sets the url for this conn., returning &mut Self for chaining
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::from(client_config());
let conn = client.get("http://localhost:9080");
let url = conn.url(); //<-
assert_eq!(url.host_str().unwrap(), "localhost");Sourcepub fn method(&self) -> Method
pub fn method(&self) -> Method
Returns a copy of the method for this conn.
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::from(client_config());
let conn = client.get("http://localhost:9080");
let method = conn.method(); //<-
assert_eq!(method, Method::Get);Sourcepub fn set_method(&mut self, method: Method) -> &mut Self
pub fn set_method(&mut self, method: Method) -> &mut Self
Sets the method for this conn., returning &mut Self for chaining
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::from(client_config());
let conn = client.get("http://localhost:9080");
let method = conn.method(); //<-
assert_eq!(method, Method::Get);Sourcepub fn request_headers(&self) -> &Headers
pub fn request_headers(&self) -> &Headers
Borrows the request headers
Sourcepub fn request_headers_mut(&mut self) -> &mut Headers
pub fn request_headers_mut(&mut self) -> &mut Headers
Mutably borrow the request headers
Sourcepub fn response_headers(&self) -> &Headers
pub fn response_headers(&self) -> &Headers
Borrows the response headers
Sourcepub fn response_headers_mut(&mut self) -> &mut Headers
pub fn response_headers_mut(&mut self) -> &mut Headers
Mutably borrow the response headers
Sourcepub fn status(&self) -> Option<Status>
pub fn status(&self) -> Option<Status>
Returns a copy of the status code for this conn.
If the conn has not yet been sent, this will be None.
use trillium_client::{Client, Status};
use trillium_testing::{client_config, with_server};
async fn handler(conn: trillium::Conn) -> trillium::Conn {
conn.with_status(418)
}
with_server(handler, |url| async move {
let client = Client::new(client_config());
let conn = client.get(url).await?;
assert_eq!(Status::ImATeapot, conn.status().unwrap());
Ok(())
});Sourcepub fn set_request_body(&mut self, body: impl Into<Body>) -> &mut Self
pub fn set_request_body(&mut self, body: impl Into<Body>) -> &mut Self
Sets the request body, returning &mut Self for chaining
env_logger::init();
use trillium_client::Client;
use trillium_testing::{client_config, with_server};
let handler = |mut conn: trillium::Conn| async move {
let body = conn.request_body_string().await.unwrap();
conn.ok(format!("request body was: {}", body))
};
with_server(handler, |url| async move {
let client = Client::from(client_config());
let mut conn = client
.post(url)
.with_body("body") //<-
.await?;
assert_eq!(
conn.response_body().read_string().await?,
"request body was: body"
);
Ok(())
});Sourcepub fn take_request_body(&mut self) -> Option<Body>
pub fn take_request_body(&mut self) -> Option<Body>
Takes the request body, leaving a None in its place
env_logger::init();
use trillium_client::Client;
use trillium_testing::{client_config, with_server};
let handler = |mut conn: trillium::Conn| async move {
let body = conn.request_body_string().await.unwrap();
conn.ok(format!("request body was: {}", body))
};
with_server(handler, |url| async move {
let client = Client::from(client_config());
let mut conn = client
.post(url)
.with_body("body") //<-
.await?;
assert_eq!(
conn.response_body().read_string().await?,
"request body was: body"
);
Ok(())
});Sourcepub fn timeout(&self) -> Option<Duration>
pub fn timeout(&self) -> Option<Duration>
Returns a copy of the timeout for this conn
this can also be set on the client with Client::set_timeout
and Client::with_timeout
Sourcepub fn timeout_mut(&mut self) -> Option<&mut Duration>
pub fn timeout_mut(&mut self) -> Option<&mut Duration>
Mutably borrow the timeout for this conn
this can also be set on the client with Client::set_timeout
and Client::with_timeout
Sourcepub fn set_timeout(&mut self, timeout: Duration) -> &mut Self
pub fn set_timeout(&mut self, timeout: Duration) -> &mut Self
Sets the timeout for this conn, returning &mut Self for chaining
this can also be set on the client with Client::set_timeout
and Client::with_timeout
Sourcepub fn take_timeout(&mut self) -> Option<Duration>
pub fn take_timeout(&mut self) -> Option<Duration>
Takes the timeout for this conn, leaving a None in its place
this can also be set on the client with Client::set_timeout
and Client::with_timeout
Sourcepub fn http_version(&self) -> Version
pub fn http_version(&self) -> Version
Returns a copy of the http version for this conn
Pre-execution this is the version hint (prior knowledge), not the version that will
necessarily be on the wire — the default Version::Http1_1 means “no hint, use
auto-discovery” rather than “force HTTP/1.1.” Post-execution this reflects the version
the request was actually sent over.
See the crate-level Protocol selection documentation for the full hint → behavior table.
Sourcepub fn set_http_version(&mut self, http_version: Version) -> &mut Self
pub fn set_http_version(&mut self, http_version: Version) -> &mut Self
Sets the http version for this conn, returning &mut Self for chaining
Pre-execution this is the version hint (prior knowledge), not the version that will
necessarily be on the wire — the default Version::Http1_1 means “no hint, use
auto-discovery” rather than “force HTTP/1.1.” Post-execution this reflects the version
the request was actually sent over.
See the crate-level Protocol selection documentation for the full hint → behavior table.
Borrows the :authority pseudo-header, populated during h3 header finalization
Sourcepub fn scheme(&self) -> Option<&str>
pub fn scheme(&self) -> Option<&str>
Borrows the :scheme pseudo-header, populated during h3 header finalization
Sourcepub fn path(&self) -> Option<&str>
pub fn path(&self) -> Option<&str>
Borrows the :path pseudo-header, populated during h3 header finalization
Sourcepub fn request_target(&self) -> Option<&str>
pub fn request_target(&self) -> Option<&str>
Borrows an explicit request target override, used only for OPTIONS * and CONNECT host:port
When set and the method is OPTIONS or CONNECT, this value is used as the HTTP request target instead of deriving it from the url. For all other methods, this field is ignored.
Sourcepub fn set_request_target(
&mut self,
request_target: impl Into<Cow<'static, str>>,
) -> &mut Self
pub fn set_request_target( &mut self, request_target: impl Into<Cow<'static, str>>, ) -> &mut Self
Sets an explicit request target override, used only for OPTIONS * and CONNECT host:port, returning &mut Self for chaining
When set and the method is OPTIONS or CONNECT, this value is used as the HTTP request target instead of deriving it from the url. For all other methods, this field is ignored.
Sourcepub fn protocol(&self) -> Option<&str>
pub fn protocol(&self) -> Option<&str>
Borrows the :protocol pseudo-header for an extended-CONNECT bootstrap (RFC 8441 §4 over h2,
RFC 9220 §3 over h3). Set internally by Conn::into_websocket to "websocket";
triggers the h2/h3 exec paths to send HEADERS without END_STREAM and leave the stream
open as a bidirectional byte channel.
Only meaningful when method is CONNECT and http_version is
Http2 or Http3. h1 and prior-version requests ignore this field.
Sourcepub fn request_trailers(&self) -> Option<&Headers>
pub fn request_trailers(&self) -> Option<&Headers>
Borrows trailers sent with the request body, populated after the body has been fully sent.
Only present when the request body was constructed with Body::new_with_trailers and
the body has been fully sent. For H3, this is populated after send_h3_request; for H1,
after send_body with a chunked body.
Sourcepub fn response_trailers(&self) -> Option<&Headers>
pub fn response_trailers(&self) -> Option<&Headers>
Borrows trailers received with the response body, populated after the response body has been fully read.
For H3, these are decoded from the trailing HEADERS frame. For H1, from chunked trailers (once H1 trailer receive is implemented).
Sourcepub fn response_body(&mut self) -> ResponseBody<'_>
pub fn response_body(&mut self) -> ResponseBody<'_>
returns a ResponseBody that borrows the connection inside this
conn.
use trillium_client::Client;
use trillium_testing::{client_config, with_server};
let handler = |mut conn: trillium::Conn| async move { conn.ok("hello from trillium") };
with_server(handler, |url| async move {
let client = Client::from(client_config());
let mut conn = client.get(url).await?;
let response_body = conn.response_body(); //<-
assert_eq!(19, response_body.content_length().unwrap());
let string = response_body.read_string().await?;
assert_eq!("hello from trillium", string);
Ok(())
});Sourcepub async fn response_json<T>(&mut self) -> Result<T, ClientSerdeError>where
T: DeserializeOwned,
Available on crate feature sonic-rs only.
pub async fn response_json<T>(&mut self) -> Result<T, ClientSerdeError>where
T: DeserializeOwned,
sonic-rs only.Attempt to deserialize the response body. Note that this consumes the body content.
Sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
attempts to retrieve the connected peer address
Sourcepub fn insert_state<T: Send + Sync + 'static>(&mut self, state: T) -> Option<T>
pub fn insert_state<T: Send + Sync + 'static>(&mut self, state: T) -> Option<T>
add state to the client conn, returning any previously set state of this type
Sourcepub fn take_state<T: Send + Sync + 'static>(&mut self) -> Option<T>
pub fn take_state<T: Send + Sync + 'static>(&mut self) -> Option<T>
take state
Trait Implementations§
Source§impl Debug for WebSocketUpgradeError
impl Debug for WebSocketUpgradeError
Source§impl Deref for WebSocketUpgradeError
impl Deref for WebSocketUpgradeError
Source§impl DerefMut for WebSocketUpgradeError
impl DerefMut for WebSocketUpgradeError
Source§impl Display for WebSocketUpgradeError
impl Display for WebSocketUpgradeError
Source§impl Error for WebSocketUpgradeError
impl Error for WebSocketUpgradeError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()