From 137e95e873f8114702fe5ff8123d532400cbc926 Mon Sep 17 00:00:00 2001 From: Shreyas Date: Fri, 8 Aug 2025 13:51:46 +0530 Subject: [PATCH] fix(relay): expand MIME type support (#5306) This fixes file uploads incorrectly showing MIME type as "Other" instead of their actual content types by expanding the `MediaType` enum relay to include common audio, video, and image formats. Basically `MediaType` enum is used for both `ContentType` which would map to `ContentType` from `hoppscotch-data` (e.g. `multipart/form-data`) but also to `FormValue` in `interop` ```rust pub enum FormValue { ... File { filename: String, content_type: MediaType, data: Bytes, }, } ``` although the later should be much more pervasive. This is a follow up on #5244 Closes FE-887 Closes #3810 Closes #5223 Closes #5233 The issue occurred because the `relay`'s `MediaType` couldn't deserialize beyond the basic types (text, JSON, XML, etc.), lacked support for other media file types. The TypeScript layer correctly detected MIME types (e.g., "audio/x-m4a"), but the deserialization process fell back to `MediaType::Other`. Main reason for servers performing strict MIME validation to reject uploads. --- .../hoppscotch-agent/src-tauri/Cargo.lock | 2 +- .../plugin-workspace/relay/src/interop.rs | 86 ++++++++++++++++++- .../tauri-plugin-relay/Cargo.lock | 2 +- .../hoppscotch-desktop/src-tauri/Cargo.lock | 4 +- .../hoppscotch-desktop/src-tauri/Cargo.toml | 2 +- packages/hoppscotch-kernel/package.json | 2 +- pnpm-lock.yaml | 10 +-- 7 files changed, 94 insertions(+), 14 deletions(-) diff --git a/packages/hoppscotch-agent/src-tauri/Cargo.lock b/packages/hoppscotch-agent/src-tauri/Cargo.lock index 1e2d129e..5837dcf4 100644 --- a/packages/hoppscotch-agent/src-tauri/Cargo.lock +++ b/packages/hoppscotch-agent/src-tauri/Cargo.lock @@ -4110,7 +4110,7 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "relay" version = "0.1.1" -source = "git+https://github.com/CuriousCorrelation/relay.git#dfa662f2e8a2731cd21c59b2a10bfc6e2ef70ca3" +source = "git+https://github.com/CuriousCorrelation/relay.git#10aca0e5d74515a6fed231ee9d7220a014f8b184" dependencies = [ "bytes", "curl", diff --git a/packages/hoppscotch-desktop/plugin-workspace/relay/src/interop.rs b/packages/hoppscotch-desktop/plugin-workspace/relay/src/interop.rs index df415212..73604247 100644 --- a/packages/hoppscotch-desktop/plugin-workspace/relay/src/interop.rs +++ b/packages/hoppscotch-desktop/plugin-workspace/relay/src/interop.rs @@ -8,6 +8,7 @@ use time::OffsetDateTime; #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Display, EnumString)] pub enum MediaType { + // Text #[serde(rename = "text/plain")] #[strum(to_string = "text/plain")] TextPlain, @@ -20,6 +21,11 @@ pub enum MediaType { #[serde(rename = "text/csv")] #[strum(to_string = "text/csv")] TextCsv, + #[serde(rename = "text/xml")] + #[strum(to_string = "text/xml")] + TextXml, + + // Application #[serde(rename = "application/json")] #[strum(to_string = "application/json")] Json, @@ -29,9 +35,6 @@ pub enum MediaType { #[serde(rename = "application/xml")] #[strum(to_string = "application/xml")] Xml, - #[serde(rename = "text/xml")] - #[strum(to_string = "text/xml")] - TextXml, #[serde(rename = "application/x-www-form-urlencoded")] #[strum(to_string = "application/x-www-form-urlencoded")] FormUrlEncoded, @@ -41,6 +44,83 @@ pub enum MediaType { #[serde(rename = "application/octet-stream")] #[strum(to_string = "application/octet-stream")] OctetStream, + #[serde(rename = "application/pdf")] + #[strum(to_string = "application/pdf")] + ApplicationPdf, + #[serde(rename = "application/zip")] + #[strum(to_string = "application/zip")] + ApplicationZip, + #[serde(rename = "application/javascript")] + #[strum(to_string = "application/javascript")] + ApplicationJavascript, + + // Audio + #[serde(rename = "audio/mpeg")] + #[strum(to_string = "audio/mpeg")] + AudioMpeg, + #[serde(rename = "audio/mp4")] + #[strum(to_string = "audio/mp4")] + AudioMp4, + #[serde(rename = "audio/x-m4a")] + #[strum(to_string = "audio/x-m4a")] + AudioXM4a, + #[serde(rename = "audio/wav")] + #[strum(to_string = "audio/wav")] + AudioWav, + #[serde(rename = "audio/ogg")] + #[strum(to_string = "audio/ogg")] + AudioOgg, + #[serde(rename = "audio/aac")] + #[strum(to_string = "audio/aac")] + AudioAac, + #[serde(rename = "audio/flac")] + #[strum(to_string = "audio/flac")] + AudioFlac, + + // Video + #[serde(rename = "video/mp4")] + #[strum(to_string = "video/mp4")] + VideoMp4, + #[serde(rename = "video/avi")] + #[strum(to_string = "video/avi")] + VideoAvi, + #[serde(rename = "video/quicktime")] + #[strum(to_string = "video/quicktime")] + VideoQuicktime, + #[serde(rename = "video/x-msvideo")] + #[strum(to_string = "video/x-msvideo")] + VideoXMsvideo, + #[serde(rename = "video/webm")] + #[strum(to_string = "video/webm")] + VideoWebm, + #[serde(rename = "video/x-flv")] + #[strum(to_string = "video/x-flv")] + VideoXFlv, + + // Image + #[serde(rename = "image/png")] + #[strum(to_string = "image/png")] + ImagePng, + #[serde(rename = "image/jpeg")] + #[strum(to_string = "image/jpeg")] + ImageJpeg, + #[serde(rename = "image/gif")] + #[strum(to_string = "image/gif")] + ImageGif, + #[serde(rename = "image/svg+xml")] + #[strum(to_string = "image/svg+xml")] + ImageSvgXml, + #[serde(rename = "image/webp")] + #[strum(to_string = "image/webp")] + ImageWebp, + #[serde(rename = "image/bmp")] + #[strum(to_string = "image/bmp")] + ImageBmp, + #[serde(rename = "image/x-icon")] + #[strum(to_string = "image/x-icon")] + ImageXIcon, + + // Fallback for unknown #[serde(other)] Other, } diff --git a/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-relay/Cargo.lock b/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-relay/Cargo.lock index 3c53f963..139218b3 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#dfa662f2e8a2731cd21c59b2a10bfc6e2ef70ca3" +source = "git+https://github.com/CuriousCorrelation/relay.git#10aca0e5d74515a6fed231ee9d7220a014f8b184" dependencies = [ "bytes", "curl", diff --git a/packages/hoppscotch-desktop/src-tauri/Cargo.lock b/packages/hoppscotch-desktop/src-tauri/Cargo.lock index 6c06a5ab..9c10b784 100644 --- a/packages/hoppscotch-desktop/src-tauri/Cargo.lock +++ b/packages/hoppscotch-desktop/src-tauri/Cargo.lock @@ -4319,7 +4319,7 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "relay" version = "0.1.1" -source = "git+https://github.com/CuriousCorrelation/relay.git#dfa662f2e8a2731cd21c59b2a10bfc6e2ef70ca3" +source = "git+https://github.com/CuriousCorrelation/relay.git#10aca0e5d74515a6fed231ee9d7220a014f8b184" dependencies = [ "bytes", "curl", @@ -5495,7 +5495,7 @@ dependencies = [ [[package]] name = "tauri-plugin-relay" version = "0.1.0" -source = "git+https://github.com/CuriousCorrelation/tauri-plugin-relay?rev=0147ac1bb29d3b88d6652432a482bd86f0174506#0147ac1bb29d3b88d6652432a482bd86f0174506" +source = "git+https://github.com/CuriousCorrelation/tauri-plugin-relay?rev=4ed4fcafeb93856591e8a36522f6ec6e340e4dc5#4ed4fcafeb93856591e8a36522f6ec6e340e4dc5" dependencies = [ "relay", "serde", diff --git a/packages/hoppscotch-desktop/src-tauri/Cargo.toml b/packages/hoppscotch-desktop/src-tauri/Cargo.toml index 2e504003..044bf903 100644 --- a/packages/hoppscotch-desktop/src-tauri/Cargo.toml +++ b/packages/hoppscotch-desktop/src-tauri/Cargo.toml @@ -30,7 +30,7 @@ tauri-plugin-dialog = "2.2.0" tauri-plugin-fs = "2.2.0" tauri-plugin-deep-link = "2.2.0" tauri-plugin-appload = { git = "https://github.com/CuriousCorrelation/tauri-plugin-appload", rev = "1b52e49d881926135838cf6cfebdc1643a9bec31" } -tauri-plugin-relay = { git = "https://github.com/CuriousCorrelation/tauri-plugin-relay", rev = "0147ac1bb29d3b88d6652432a482bd86f0174506" } +tauri-plugin-relay = { git = "https://github.com/CuriousCorrelation/tauri-plugin-relay", rev = "4ed4fcafeb93856591e8a36522f6ec6e340e4dc5" } axum = "0.8.1" tower-http = { version = "0.6.2", features = ["cors"] } random-port = "0.1.1" diff --git a/packages/hoppscotch-kernel/package.json b/packages/hoppscotch-kernel/package.json index 0b439ee1..11b09134 100644 --- a/packages/hoppscotch-kernel/package.json +++ b/packages/hoppscotch-kernel/package.json @@ -57,6 +57,6 @@ "@tauri-apps/plugin-dialog": "2.0.1", "@tauri-apps/plugin-fs": "2.0.2", "@tauri-apps/plugin-store": "2.2.0", - "@hoppscotch/plugin-relay": "github:CuriousCorrelation/tauri-plugin-relay#0147ac1bb29d3b88d6652432a482bd86f0174506" + "@hoppscotch/plugin-relay": "github:CuriousCorrelation/tauri-plugin-relay#4ed4fcafeb93856591e8a36522f6ec6e340e4dc5" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 04ed9f05..6e0ec68b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1236,8 +1236,8 @@ importers: packages/hoppscotch-kernel: dependencies: '@hoppscotch/plugin-relay': - specifier: github:CuriousCorrelation/tauri-plugin-relay#0147ac1bb29d3b88d6652432a482bd86f0174506 - version: '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/0147ac1bb29d3b88d6652432a482bd86f0174506' + specifier: github:CuriousCorrelation/tauri-plugin-relay#4ed4fcafeb93856591e8a36522f6ec6e340e4dc5 + version: '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/4ed4fcafeb93856591e8a36522f6ec6e340e4dc5' '@tauri-apps/api': specifier: 2.1.1 version: 2.1.1 @@ -1883,8 +1883,8 @@ packages: resolution: {tarball: https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/1b52e49d881926135838cf6cfebdc1643a9bec31} version: 0.1.0 - '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/0147ac1bb29d3b88d6652432a482bd86f0174506': - resolution: {tarball: https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/0147ac1bb29d3b88d6652432a482bd86f0174506} + '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/4ed4fcafeb93856591e8a36522f6ec6e340e4dc5': + resolution: {tarball: https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/4ed4fcafeb93856591e8a36522f6ec6e340e4dc5} version: 0.1.0 '@alloc/quick-lru@5.2.0': @@ -14878,7 +14878,7 @@ snapshots: dependencies: '@tauri-apps/api': 2.1.1 - '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/0147ac1bb29d3b88d6652432a482bd86f0174506': + '@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/4ed4fcafeb93856591e8a36522f6ec6e340e4dc5': dependencies: '@tauri-apps/api': 2.1.1