Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
fix(websocket): Fix websocket upgrade builder (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x676e67 authored Sep 8, 2024
1 parent 7255536 commit 111d928
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
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

0 comments on commit 111d928

Please sign in to comment.