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.
This commit is contained in:
parent
eb2cc58dca
commit
137e95e873
7 changed files with 94 additions and 14 deletions
2
packages/hoppscotch-agent/src-tauri/Cargo.lock
generated
2
packages/hoppscotch-agent/src-tauri/Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
4
packages/hoppscotch-desktop/src-tauri/Cargo.lock
generated
4
packages/hoppscotch-desktop/src-tauri/Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue