Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(websocket): Fix websocket upgrade builder #134

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let websocket = Client::ws_builder()
let websocket = Client::builder()
.impersonate(Impersonate::Chrome127)
.http1_only()
.build()?
.get("wss://echo.websocket.org")
.upgrade()
Expand Down
8 changes: 0 additions & 8 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,14 +1252,6 @@ impl Client {
ClientBuilder::new()
}

/// Create a `ClientBuilder` to configure a `Client`.
///
/// This is required http1 only.
#[cfg(feature = "boring-tls")]
pub fn ws_builder() -> ClientBuilder {
Self::builder().http1_only()
}

/// Convenience method to make a `GET` request to a URL.
///
/// # Errors
Expand Down
9 changes: 8 additions & 1 deletion src/client/websocket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod json;
mod message;

use std::{
ops::{Deref, DerefMut},
pin::Pin,
task::{Context, Poll},
};
Expand Down Expand Up @@ -181,14 +182,20 @@ pub struct WebSocketResponse {
config: WebSocketConfig,
}

impl std::ops::Deref for WebSocketResponse {
impl Deref for WebSocketResponse {
type Target = Response;

fn deref(&self) -> &Self::Target {
&self.inner
}
}

impl DerefMut for WebSocketResponse {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}

impl WebSocketResponse {
/// Turns the response into a websocket. This checks if the websocket
/// handshake was successful.
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//! let websocket = Client::ws_builder()
//! let websocket = Client::builder()
//! .impersonate(Impersonate::Chrome127)
//!
//! .build()?
//! .get("wss://echo.websocket.org")
//! .upgrade()
Expand Down Expand Up @@ -380,7 +381,8 @@ pub async fn get<T: IntoUrl>(url: T) -> crate::Result<Response> {
/// response into a websocket.
#[cfg(feature = "websocket")]
pub async fn websocket<T: IntoUrl>(url: T) -> crate::Result<WebSocket> {
Client::ws_builder()
Client::builder()
.http1_only()
.build()?
.get(url)
.upgrade()
Expand Down