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]]
name = "epoxy-client"
version = "2.0.0"
version = "2.0.2"
dependencies = [
"async-compression",
"async-trait",

View file

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

View file

@ -1,6 +1,6 @@
{
"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",
"scripts": {
"build": "./build.sh"

View file

@ -247,7 +247,7 @@ impl EpoxyClient {
protocols: Vec<String>,
headers: JsValue,
) -> 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(

View file

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