add useragent to ws requests

This commit is contained in:
Toshit Chawda 2024-07-02 21:09:09 -07:00
parent 0aec6e563c
commit b5263a06fa
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
5 changed files with 8 additions and 6 deletions

2
Cargo.lock generated
View file

@ -522,7 +522,7 @@ checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b"
[[package]] [[package]]
name = "epoxy-client" name = "epoxy-client"
version = "2.0.0" version = "2.0.2"
dependencies = [ dependencies = [
"async-compression", "async-compression",
"async-trait", "async-trait",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "epoxy-client" name = "epoxy-client"
version = "2.0.1" version = "2.0.2"
edition = "2021" edition = "2021"
[lib] [lib]

View file

@ -1,6 +1,6 @@
{ {
"name": "@mercuryworkshop/epoxy-tls", "name": "@mercuryworkshop/epoxy-tls",
"version": "2.0.1-1", "version": "2.0.2-1",
"description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser", "description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser",
"scripts": { "scripts": {
"build": "./build.sh" "build": "./build.sh"

View file

@ -247,7 +247,7 @@ impl EpoxyClient {
protocols: Vec<String>, protocols: Vec<String>,
headers: JsValue, headers: JsValue,
) -> Result<EpoxyWebSocket, EpoxyError> { ) -> Result<EpoxyWebSocket, EpoxyError> {
EpoxyWebSocket::connect(self, handlers, url, protocols, headers).await EpoxyWebSocket::connect(self, handlers, url, protocols, headers, &self.user_agent).await
} }
pub async fn connect_tcp( pub async fn connect_tcp(

View file

@ -9,7 +9,7 @@ use futures_util::lock::Mutex;
use getrandom::getrandom; use getrandom::getrandom;
use http::{ use http::{
header::{ header::{
CONNECTION, HOST, SEC_WEBSOCKET_KEY, SEC_WEBSOCKET_PROTOCOL, SEC_WEBSOCKET_VERSION, UPGRADE, CONNECTION, HOST, SEC_WEBSOCKET_KEY, SEC_WEBSOCKET_PROTOCOL, SEC_WEBSOCKET_VERSION, UPGRADE, USER_AGENT,
}, },
Method, Request, Response, StatusCode, Uri, Method, Request, Response, StatusCode, Uri,
}; };
@ -38,6 +38,7 @@ impl EpoxyWebSocket {
url: String, url: String,
protocols: Vec<String>, protocols: Vec<String>,
headers: JsValue, headers: JsValue,
user_agent: &str,
) -> Result<Self, EpoxyError> { ) -> Result<Self, EpoxyError> {
let EpoxyHandlers { let EpoxyHandlers {
onopen, onopen,
@ -61,7 +62,8 @@ impl EpoxyWebSocket {
.header(CONNECTION, "upgrade") .header(CONNECTION, "upgrade")
.header(UPGRADE, "websocket") .header(UPGRADE, "websocket")
.header(SEC_WEBSOCKET_KEY, key) .header(SEC_WEBSOCKET_KEY, key)
.header(SEC_WEBSOCKET_VERSION, "13"); .header(SEC_WEBSOCKET_VERSION, "13")
.header(USER_AGENT, user_agent);
if !protocols.is_empty() { if !protocols.is_empty() {
request = request.header(SEC_WEBSOCKET_PROTOCOL, protocols.join(",")); request = request.header(SEC_WEBSOCKET_PROTOCOL, protocols.join(","));