Skip to content
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
6 changes: 6 additions & 0 deletions rnet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1168,10 +1168,16 @@ class WebSocketParams:
"""
proxy: typing.Optional[builtins.str]
interface: typing.Optional[builtins.str]
protocols: typing.Optional[builtins.list[builtins.str]]
auth: typing.Optional[builtins.str]
bearer_auth: typing.Optional[builtins.str]
basic_auth: typing.Optional[tuple[builtins.str, typing.Optional[builtins.str]]]
query: typing.Optional[builtins.list[tuple[builtins.str, builtins.str]]]
write_buffer_size: typing.Optional[builtins.int]
max_write_buffer_size: typing.Optional[builtins.int]
max_message_size: typing.Optional[builtins.int]
max_frame_size: typing.Optional[builtins.int]
accept_unmasked_frames: typing.Optional[builtins.bool]

def delete(url:builtins.str, **kwds) -> typing.Any:
r"""
Expand Down
32 changes: 32 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,38 @@ async fn execute_websocket_request(
// The protocols to use for the request.
apply_option!(apply_if_some, builder, params.protocols, protocols);

// The WebSocket config
apply_option!(
apply_if_some,
builder,
params.write_buffer_size,
write_buffer_size
);
apply_option!(
apply_if_some,
builder,
params.max_write_buffer_size,
max_write_buffer_size
);
apply_option!(
apply_if_some,
builder,
params.max_frame_size,
max_frame_size
);
apply_option!(
apply_if_some,
builder,
params.max_message_size,
max_message_size
);
apply_option!(
apply_if_some,
builder,
params.accept_unmasked_frames,
accept_unmasked_frames
);

// The origin to use for the request.
builder = builder.with_builder(|mut builder| {
// Network options.
Expand Down
52 changes: 52 additions & 0 deletions src/param/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct WebSocketParams {
pub headers: Option<IndexMap<String, String>>,

/// The protocols to use for the request.
#[pyo3(get)]
pub protocols: Option<Vec<String>>,

/// The authentication to use for the request.
Expand All @@ -66,6 +67,51 @@ pub struct WebSocketParams {
/// The query parameters to use for the request.
#[pyo3(get)]
pub query: Option<Vec<(String, String)>>,

/// The target minimum size of the write buffer to reach before writing the data
/// to the underlying stream.
/// The default value is 128 KiB.
///
/// If set to `0` each message will be eagerly written to the underlying stream.
/// It is often more optimal to allow them to buffer a little, hence the default value.
///
/// Note: [`flush`](WebSocket::flush) will always fully write the buffer regardless.
#[pyo3(get)]
pub write_buffer_size: Option<usize>,

/// The max size of the write buffer in bytes. Setting this can provide backpressure
/// in the case the write buffer is filling up due to write errors.
/// The default value is unlimited.
///
/// Note: The write buffer only builds up past [`write_buffer_size`](Self::write_buffer_size)
/// when writes to the underlying stream are failing. So the **write buffer can not
/// fill up if you are not observing write errors even if not flushing**.
///
/// Note: Should always be at least [`write_buffer_size + 1 message`](Self::write_buffer_size)
/// and probably a little more depending on error handling strategy.
#[pyo3(get)]
pub max_write_buffer_size: Option<usize>,

/// The maximum size of an incoming message. `None` means no size limit. The default value is 64 MiB
/// which should be reasonably big for all normal use-cases but small enough to prevent
/// memory eating by a malicious user.
#[pyo3(get)]
pub max_message_size: Option<usize>,

/// The maximum size of a single incoming message frame. `None` means no size limit. The limit is for
/// frame payload NOT including the frame header. The default value is 16 MiB which should
/// be reasonably big for all normal use-cases but small enough to prevent memory eating
/// by a malicious user.
#[pyo3(get)]
pub max_frame_size: Option<usize>,

/// When set to `true`, the server will accept and handle unmasked frames
/// from the client. According to the RFC 6455, the server must close the
/// connection to the client in such cases, however it seems like there are
/// some popular libraries that are sending unmasked frames, ignoring the RFC.
/// By default this option is set to `false`, i.e. according to RFC 6455.
#[pyo3(get)]
pub accept_unmasked_frames: Option<bool>,
}

macro_rules! extract_option {
Expand All @@ -89,6 +135,12 @@ impl<'py> FromPyObject<'py> for WebSocketParams {
extract_option!(ob, params, bearer_auth);
extract_option!(ob, params, basic_auth);
extract_option!(ob, params, query);

extract_option!(ob, params, write_buffer_size);
extract_option!(ob, params, max_write_buffer_size);
extract_option!(ob, params, max_message_size);
extract_option!(ob, params, max_frame_size);
extract_option!(ob, params, accept_unmasked_frames);
Ok(params)
}
}