Skip to content

Commit 137e95e

Browse files
fix(relay): expand MIME type support (hoppscotch#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 hoppscotch#5244 Closes FE-887 Closes hoppscotch#3810 Closes hoppscotch#5223 Closes hoppscotch#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.
1 parent eb2cc58 commit 137e95e

File tree

7 files changed

+94
-14
lines changed

7 files changed

+94
-14
lines changed

packages/hoppscotch-agent/src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hoppscotch-desktop/plugin-workspace/relay/src/interop.rs

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use time::OffsetDateTime;
88

99
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Display, EnumString)]
1010
pub enum MediaType {
11+
// Text
1112
#[serde(rename = "text/plain")]
1213
#[strum(to_string = "text/plain")]
1314
TextPlain,
@@ -20,6 +21,11 @@ pub enum MediaType {
2021
#[serde(rename = "text/csv")]
2122
#[strum(to_string = "text/csv")]
2223
TextCsv,
24+
#[serde(rename = "text/xml")]
25+
#[strum(to_string = "text/xml")]
26+
TextXml,
27+
28+
// Application
2329
#[serde(rename = "application/json")]
2430
#[strum(to_string = "application/json")]
2531
Json,
@@ -29,9 +35,6 @@ pub enum MediaType {
2935
#[serde(rename = "application/xml")]
3036
#[strum(to_string = "application/xml")]
3137
Xml,
32-
#[serde(rename = "text/xml")]
33-
#[strum(to_string = "text/xml")]
34-
TextXml,
3538
#[serde(rename = "application/x-www-form-urlencoded")]
3639
#[strum(to_string = "application/x-www-form-urlencoded")]
3740
FormUrlEncoded,
@@ -41,6 +44,83 @@ pub enum MediaType {
4144
#[serde(rename = "application/octet-stream")]
4245
#[strum(to_string = "application/octet-stream")]
4346
OctetStream,
47+
#[serde(rename = "application/pdf")]
48+
#[strum(to_string = "application/pdf")]
49+
ApplicationPdf,
50+
#[serde(rename = "application/zip")]
51+
#[strum(to_string = "application/zip")]
52+
ApplicationZip,
53+
#[serde(rename = "application/javascript")]
54+
#[strum(to_string = "application/javascript")]
55+
ApplicationJavascript,
56+
57+
// Audio
58+
#[serde(rename = "audio/mpeg")]
59+
#[strum(to_string = "audio/mpeg")]
60+
AudioMpeg,
61+
#[serde(rename = "audio/mp4")]
62+
#[strum(to_string = "audio/mp4")]
63+
AudioMp4,
64+
#[serde(rename = "audio/x-m4a")]
65+
#[strum(to_string = "audio/x-m4a")]
66+
AudioXM4a,
67+
#[serde(rename = "audio/wav")]
68+
#[strum(to_string = "audio/wav")]
69+
AudioWav,
70+
#[serde(rename = "audio/ogg")]
71+
#[strum(to_string = "audio/ogg")]
72+
AudioOgg,
73+
#[serde(rename = "audio/aac")]
74+
#[strum(to_string = "audio/aac")]
75+
AudioAac,
76+
#[serde(rename = "audio/flac")]
77+
#[strum(to_string = "audio/flac")]
78+
AudioFlac,
79+
80+
// Video
81+
#[serde(rename = "video/mp4")]
82+
#[strum(to_string = "video/mp4")]
83+
VideoMp4,
84+
#[serde(rename = "video/avi")]
85+
#[strum(to_string = "video/avi")]
86+
VideoAvi,
87+
#[serde(rename = "video/quicktime")]
88+
#[strum(to_string = "video/quicktime")]
89+
VideoQuicktime,
90+
#[serde(rename = "video/x-msvideo")]
91+
#[strum(to_string = "video/x-msvideo")]
92+
VideoXMsvideo,
93+
#[serde(rename = "video/webm")]
94+
#[strum(to_string = "video/webm")]
95+
VideoWebm,
96+
#[serde(rename = "video/x-flv")]
97+
#[strum(to_string = "video/x-flv")]
98+
VideoXFlv,
99+
100+
// Image
101+
#[serde(rename = "image/png")]
102+
#[strum(to_string = "image/png")]
103+
ImagePng,
104+
#[serde(rename = "image/jpeg")]
105+
#[strum(to_string = "image/jpeg")]
106+
ImageJpeg,
107+
#[serde(rename = "image/gif")]
108+
#[strum(to_string = "image/gif")]
109+
ImageGif,
110+
#[serde(rename = "image/svg+xml")]
111+
#[strum(to_string = "image/svg+xml")]
112+
ImageSvgXml,
113+
#[serde(rename = "image/webp")]
114+
#[strum(to_string = "image/webp")]
115+
ImageWebp,
116+
#[serde(rename = "image/bmp")]
117+
#[strum(to_string = "image/bmp")]
118+
ImageBmp,
119+
#[serde(rename = "image/x-icon")]
120+
#[strum(to_string = "image/x-icon")]
121+
ImageXIcon,
122+
123+
// Fallback for unknown
44124
#[serde(other)]
45125
Other,
46126
}

packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-relay/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hoppscotch-desktop/src-tauri/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hoppscotch-desktop/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tauri-plugin-dialog = "2.2.0"
3030
tauri-plugin-fs = "2.2.0"
3131
tauri-plugin-deep-link = "2.2.0"
3232
tauri-plugin-appload = { git = "https://github.com/CuriousCorrelation/tauri-plugin-appload", rev = "1b52e49d881926135838cf6cfebdc1643a9bec31" }
33-
tauri-plugin-relay = { git = "https://github.com/CuriousCorrelation/tauri-plugin-relay", rev = "0147ac1bb29d3b88d6652432a482bd86f0174506" }
33+
tauri-plugin-relay = { git = "https://github.com/CuriousCorrelation/tauri-plugin-relay", rev = "4ed4fcafeb93856591e8a36522f6ec6e340e4dc5" }
3434
axum = "0.8.1"
3535
tower-http = { version = "0.6.2", features = ["cors"] }
3636
random-port = "0.1.1"

packages/hoppscotch-kernel/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
"@tauri-apps/plugin-dialog": "2.0.1",
5858
"@tauri-apps/plugin-fs": "2.0.2",
5959
"@tauri-apps/plugin-store": "2.2.0",
60-
"@hoppscotch/plugin-relay": "github:CuriousCorrelation/tauri-plugin-relay#0147ac1bb29d3b88d6652432a482bd86f0174506"
60+
"@hoppscotch/plugin-relay": "github:CuriousCorrelation/tauri-plugin-relay#4ed4fcafeb93856591e8a36522f6ec6e340e4dc5"
6161
}
6262
}

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)