Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix(relay): better matching for `content-type` detection (#5025)
Shreyas8c6ec87f90f6
diff --git a/packages/hoppscotch-agent/package.json b/packages/hoppscotch-agent/package.jsonindex 09c8442e4..e134f58b7 100644--- a/packages/hoppscotch-agent/package.json+++ b/packages/hoppscotch-agent/package.json@@ -1,7 +1,7 @@{"name": "hoppscotch-agent","private": true,- "version": "0.1.9",+ "version": "0.1.10","type": "module","scripts": {"dev": "vite",diff --git a/packages/hoppscotch-agent/src-tauri/Cargo.lock b/packages/hoppscotch-agent/src-tauri/Cargo.lockindex 48167ab8f..d860708a0 100644--- a/packages/hoppscotch-agent/src-tauri/Cargo.lock+++ b/packages/hoppscotch-agent/src-tauri/Cargo.lock@@ -2066,7 +2066,7 @@ dependencies = [[[package]]name = "hoppscotch-agent"-version = "0.1.9"+version = "0.1.10"dependencies = ["aes-gcm","axum",@@ -4098,7 +4098,7 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"[[package]]name = "relay"version = "0.1.1"-source = "git+https://github.com/CuriousCorrelation/relay.git#cac0d123d0f7ff6971edacf5809c120d5378c25e"+source = "git+https://github.com/CuriousCorrelation/relay.git#dfa662f2e8a2731cd21c59b2a10bfc6e2ef70ca3"dependencies = ["bytes","curl",diff --git a/packages/hoppscotch-agent/src-tauri/Cargo.toml b/packages/hoppscotch-agent/src-tauri/Cargo.tomlindex 6c90c2911..0c9086deb 100644--- a/packages/hoppscotch-agent/src-tauri/Cargo.toml+++ b/packages/hoppscotch-agent/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "hoppscotch-agent"-version = "0.1.9"+version = "0.1.10"description = "A cross-platform HTTP request agent for Hoppscotch for advanced request handling including custom headers, certificates, proxies, and local system integration."authors = ["AndrewBastin", "CuriousCorrelation"]edition = "2021"diff --git a/packages/hoppscotch-agent/src-tauri/tauri.conf.json b/packages/hoppscotch-agent/src-tauri/tauri.conf.jsonindex 55a603f29..ba1964aaa 100644--- a/packages/hoppscotch-agent/src-tauri/tauri.conf.json+++ b/packages/hoppscotch-agent/src-tauri/tauri.conf.json@@ -1,7 +1,7 @@{"$schema": "https://schema.tauri.app/config/2.0.0-rc","productName": "Hoppscotch Agent",- "version": "0.1.9",+ "version": "0.1.10","identifier": "io.hoppscotch.agent","build": {"beforeDevCommand": "pnpm dev",diff --git a/packages/hoppscotch-agent/src-tauri/tauri.portable.conf.json b/packages/hoppscotch-agent/src-tauri/tauri.portable.conf.jsonindex 5a536f464..062f606a0 100644--- a/packages/hoppscotch-agent/src-tauri/tauri.portable.conf.json+++ b/packages/hoppscotch-agent/src-tauri/tauri.portable.conf.json@@ -1,7 +1,7 @@{"$schema": "https://schema.tauri.app/config/2.0.0-rc","productName": "Hoppscotch Agent Portable",- "version": "0.1.9",+ "version": "0.1.10","identifier": "io.hoppscotch.agent","build": {"beforeDevCommand": "pnpm dev",diff --git a/packages/hoppscotch-desktop/plugin-workspace/relay/src/response.rs b/packages/hoppscotch-desktop/plugin-workspace/relay/src/response.rsindex 6c43d3a5d..a5c12d7e9 100644--- a/packages/hoppscotch-desktop/plugin-workspace/relay/src/response.rs+++ b/packages/hoppscotch-desktop/plugin-workspace/relay/src/response.rs@@ -83,25 +83,35 @@ impl ResponseHandler {fn determine_media_type(&self) -> MediaType {tracing::trace!("Determining response content type");- // TODO: Check for other capitalizations, `content-type` or `CONTENT-TYPE`self.headers- .get("Content-Type")- .and_then(|content_type| content_type.parse::<Mime>().ok())- .and_then(|mime| match (mime.type_(), mime.subtype()) {- (mime::APPLICATION, mime::JSON) => Some(MediaType::Json),- (mime::APPLICATION, name) if name == "ld+json" => Some(MediaType::JsonLd),- (mime::APPLICATION, mime::XML) => Some(MediaType::Xml),- (mime::APPLICATION, mime::WWW_FORM_URLENCODED) => Some(MediaType::FormUrlEncoded),- (mime::APPLICATION, mime::OCTET_STREAM) => Some(MediaType::OctetStream),- (mime::TEXT, mime::PLAIN) => Some(MediaType::TextPlain),- (mime::TEXT, mime::HTML) => Some(MediaType::TextHtml),- (mime::TEXT, mime::CSS) => Some(MediaType::TextCss),- (mime::TEXT, mime::CSV) => Some(MediaType::TextCsv),- (mime::TEXT, mime::XML) => Some(MediaType::TextXml),- (mime::MULTIPART, name) if name == "form-data" => {- Some(MediaType::MultipartFormData)+ .iter()+ .find_map(|(k, v)| {+ if k.to_lowercase() == "content-type" {+ v.parse::<Mime>()+ .ok()+ .and_then(|mime| match (mime.type_(), mime.subtype()) {+ (mime::APPLICATION, mime::JSON) => Some(MediaType::Json),+ (mime::APPLICATION, mime::XML) => Some(MediaType::Xml),+ (mime::APPLICATION, mime::OCTET_STREAM) => Some(MediaType::OctetStream),+ (mime::TEXT, mime::PLAIN) => Some(MediaType::TextPlain),+ (mime::TEXT, mime::HTML) => Some(MediaType::TextHtml),+ (mime::TEXT, mime::CSS) => Some(MediaType::TextCss),+ (mime::TEXT, mime::CSV) => Some(MediaType::TextCsv),+ (mime::TEXT, mime::XML) => Some(MediaType::TextXml),+ (mime::APPLICATION, mime::WWW_FORM_URLENCODED) => {+ Some(MediaType::FormUrlEncoded)+ }+ (mime::APPLICATION, name) if name == "ld+json" => {+ Some(MediaType::JsonLd)+ }+ (mime::MULTIPART, name) if name == "form-data" => {+ Some(MediaType::MultipartFormData)+ }+ _ => None,+ })+ } else {+ None}- _ => None,}).or(infer::get(&self.body).map(|kind| MediaType::from_str(kind.mime_type()).ok())diff --git a/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-relay/Cargo.lock b/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-relay/Cargo.lockindex c5ab525ec..3c53f963e 100644--- a/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-relay/Cargo.lock+++ b/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-relay/Cargo.lock@@ -2888,7 +2888,7 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"[[package]]name = "relay"version = "0.1.1"-source = "git+https://github.com/CuriousCorrelation/relay.git#cac0d123d0f7ff6971edacf5809c120d5378c25e"+source = "git+https://github.com/CuriousCorrelation/relay.git#dfa662f2e8a2731cd21c59b2a10bfc6e2ef70ca3"dependencies = ["bytes","curl",diff --git a/packages/hoppscotch-desktop/src-tauri/Cargo.lock b/packages/hoppscotch-desktop/src-tauri/Cargo.lockindex 3d8bc60f2..6442feff9 100644--- a/packages/hoppscotch-desktop/src-tauri/Cargo.lock+++ b/packages/hoppscotch-desktop/src-tauri/Cargo.lock@@ -3968,7 +3968,7 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"[[package]]name = "relay"version = "0.1.1"-source = "git+https://github.com/CuriousCorrelation/relay.git#d258a2c1557b9da0715681a1f267a686eb4920bb"+source = "git+https://github.com/CuriousCorrelation/relay.git#dfa662f2e8a2731cd21c59b2a10bfc6e2ef70ca3"dependencies = ["bytes","curl",@@ -5093,7 +5093,7 @@ dependencies = [[[package]]name = "tauri-plugin-relay"version = "0.1.0"-source = "git+https://github.com/CuriousCorrelation/tauri-plugin-relay#4b96e40170c65189144299d896b7e97803f13cca"+source = "git+https://github.com/CuriousCorrelation/tauri-plugin-relay#3273b9b075f1f6fa9171799a961c435454c0c9a2"dependencies = ["relay","serde",diff --git a/packages/hoppscotch-desktop/src-tauri/src/lib.rs b/packages/hoppscotch-desktop/src-tauri/src/lib.rsindex c7956a570..67b20e65d 100644--- a/packages/hoppscotch-desktop/src-tauri/src/lib.rs+++ b/packages/hoppscotch-desktop/src-tauri/src/lib.rs@@ -18,35 +18,24 @@ fn hopp_auth_port() -> u16 {#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {- tracing::info!("Starting Hoppscotch Desktop v{}", env!("CARGO_PKG_VERSION"));-- let server_port = portpicker::pick_unused_port().expect("Cannot find unused port");- SERVER_PORT- .set(server_port)- .expect("Failed to set server port");- tracing::info!("Selected server port: {}", server_port);-tauri::Builder::default()- .plugin(- tauri_plugin_window_state::Builder::new()- .with_state_flags(- StateFlags::SIZE- | StateFlags::POSITION- | StateFlags::MAXIMIZED- | StateFlags::FULLSCREEN,- )- .with_denylist(&["main"])- .build(),- )- .plugin(tauri_plugin_process::init())- .plugin(tauri_plugin_updater::Builder::new().build())- .plugin(tauri_plugin_store::Builder::new().build())- .plugin(tauri_plugin_deep_link::init())- .plugin(tauri_plugin_dialog::init()).setup(|app| {let handle = app.handle().clone();- tracing::info!(app_name = %app.package_info().name, "Configuring deep link handler");+ logger::setup(app.handle().clone())?;+ tracing::info!("Logger setup complete");++ let server_port = portpicker::pick_unused_port().expect("Cannot find unused port");+ tracing::info!("Selected server port: {}", server_port);+ SERVER_PORT+ .set(server_port)+ .expect("Failed to set server port");+ let port = *SERVER_PORT.get().expect("Server port not initialized");+ tracing::info!(port = port, "Initializing server with pre-selected port");+ let port = server::init(port, handle.clone());+ tracing::info!(port = port, "Server initialization complete");++ tracing::info!(app_name = %app.package_info().name, "Configuring deep link handler");app.deep_link().on_open_url(move |event| {let urls = event.urls();tracing::info!(@@ -64,24 +53,29 @@ pub fn run() {);});});- Ok(())- })- .setup(|app| {- let handle = app.handle().clone();- let port = *SERVER_PORT.get().expect("Server port not initialized");- tracing::info!(port = port, "Initializing server with pre-selected port");- let port = server::init(port, handle);- tracing::info!(port = port, "Server initialization complete");+ tracing::info!("Starting Hoppscotch Desktop v{}", env!("CARGO_PKG_VERSION"));+Ok(())})+ .plugin(+ tauri_plugin_window_state::Builder::new()+ .with_state_flags(+ StateFlags::SIZE+ | StateFlags::POSITION+ | StateFlags::MAXIMIZED+ | StateFlags::FULLSCREEN,+ )+ .with_denylist(&["main"])+ .build(),+ )+ .plugin(tauri_plugin_process::init())+ .plugin(tauri_plugin_updater::Builder::new().build())+ .plugin(tauri_plugin_store::Builder::new().build())+ .plugin(tauri_plugin_deep_link::init())+ .plugin(tauri_plugin_dialog::init()).plugin(tauri_plugin_shell::init()).plugin(tauri_plugin_fs::init())- .setup(|app| {- logger::setup(app.handle().clone())?;- tracing::info!("Logger setup complete");- Ok(())- }).plugin(tauri_plugin_appload::init(VendorConfigBuilder::new().bundle(include_bytes!("../../bundle.zip").to_vec(),diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex ac35e4393..9f34846f5 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1181,7 +1181,7 @@ importers:dependencies:'@hoppscotch/plugin-relay':specifier: github:CuriousCorrelation/tauri-plugin-relay- version: '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/68d6b2532c900b4be24a038c49eec4794e990a3d'+ version: '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/3273b9b075f1f6fa9171799a961c435454c0c9a2''@tauri-apps/api':specifier: 2.1.1version: 2.1.1@@ -1810,8 +1810,8 @@ packages:resolution: {tarball: https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/60adb82d0cc886004307057194cf680373e14e02}version: 0.1.0- '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/68d6b2532c900b4be24a038c49eec4794e990a3d':- resolution: {tarball: https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/68d6b2532c900b4be24a038c49eec4794e990a3d}+ '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/3273b9b075f1f6fa9171799a961c435454c0c9a2':+ resolution: {tarball: https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/3273b9b075f1f6fa9171799a961c435454c0c9a2}version: 0.1.0'@alloc/[email protected]':@@ -13208,7 +13208,7 @@ snapshots:dependencies:'@tauri-apps/api': 2.1.1- '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/68d6b2532c900b4be24a038c49eec4794e990a3d':+ '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/3273b9b075f1f6fa9171799a961c435454c0c9a2':dependencies:'@tauri-apps/api': 2.1.1