Skip to content

Commit 8c6ec87

Browse files
fix(relay): better matching for content-type detection (hoppscotch#5025)
1 parent decbb56 commit 8c6ec87

File tree

10 files changed

+72
-68
lines changed

10 files changed

+72
-68
lines changed

packages/hoppscotch-agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hoppscotch-agent",
33
"private": true,
4-
"version": "0.1.9",
4+
"version": "0.1.10",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

packages/hoppscotch-agent/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-agent/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hoppscotch-agent"
3-
version = "0.1.9"
3+
version = "0.1.10"
44
description = "A cross-platform HTTP request agent for Hoppscotch for advanced request handling including custom headers, certificates, proxies, and local system integration."
55
authors = ["AndrewBastin", "CuriousCorrelation"]
66
edition = "2021"

packages/hoppscotch-agent/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2.0.0-rc",
33
"productName": "Hoppscotch Agent",
4-
"version": "0.1.9",
4+
"version": "0.1.10",
55
"identifier": "io.hoppscotch.agent",
66
"build": {
77
"beforeDevCommand": "pnpm dev",

packages/hoppscotch-agent/src-tauri/tauri.portable.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2.0.0-rc",
33
"productName": "Hoppscotch Agent Portable",
4-
"version": "0.1.9",
4+
"version": "0.1.10",
55
"identifier": "io.hoppscotch.agent",
66
"build": {
77
"beforeDevCommand": "pnpm dev",

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,35 @@ impl ResponseHandler {
8383
fn determine_media_type(&self) -> MediaType {
8484
tracing::trace!("Determining response content type");
8585

86-
// TODO: Check for other capitalizations, `content-type` or `CONTENT-TYPE`
8786
self.headers
88-
.get("Content-Type")
89-
.and_then(|content_type| content_type.parse::<Mime>().ok())
90-
.and_then(|mime| match (mime.type_(), mime.subtype()) {
91-
(mime::APPLICATION, mime::JSON) => Some(MediaType::Json),
92-
(mime::APPLICATION, name) if name == "ld+json" => Some(MediaType::JsonLd),
93-
(mime::APPLICATION, mime::XML) => Some(MediaType::Xml),
94-
(mime::APPLICATION, mime::WWW_FORM_URLENCODED) => Some(MediaType::FormUrlEncoded),
95-
(mime::APPLICATION, mime::OCTET_STREAM) => Some(MediaType::OctetStream),
96-
(mime::TEXT, mime::PLAIN) => Some(MediaType::TextPlain),
97-
(mime::TEXT, mime::HTML) => Some(MediaType::TextHtml),
98-
(mime::TEXT, mime::CSS) => Some(MediaType::TextCss),
99-
(mime::TEXT, mime::CSV) => Some(MediaType::TextCsv),
100-
(mime::TEXT, mime::XML) => Some(MediaType::TextXml),
101-
(mime::MULTIPART, name) if name == "form-data" => {
102-
Some(MediaType::MultipartFormData)
87+
.iter()
88+
.find_map(|(k, v)| {
89+
if k.to_lowercase() == "content-type" {
90+
v.parse::<Mime>()
91+
.ok()
92+
.and_then(|mime| match (mime.type_(), mime.subtype()) {
93+
(mime::APPLICATION, mime::JSON) => Some(MediaType::Json),
94+
(mime::APPLICATION, mime::XML) => Some(MediaType::Xml),
95+
(mime::APPLICATION, mime::OCTET_STREAM) => Some(MediaType::OctetStream),
96+
(mime::TEXT, mime::PLAIN) => Some(MediaType::TextPlain),
97+
(mime::TEXT, mime::HTML) => Some(MediaType::TextHtml),
98+
(mime::TEXT, mime::CSS) => Some(MediaType::TextCss),
99+
(mime::TEXT, mime::CSV) => Some(MediaType::TextCsv),
100+
(mime::TEXT, mime::XML) => Some(MediaType::TextXml),
101+
(mime::APPLICATION, mime::WWW_FORM_URLENCODED) => {
102+
Some(MediaType::FormUrlEncoded)
103+
}
104+
(mime::APPLICATION, name) if name == "ld+json" => {
105+
Some(MediaType::JsonLd)
106+
}
107+
(mime::MULTIPART, name) if name == "form-data" => {
108+
Some(MediaType::MultipartFormData)
109+
}
110+
_ => None,
111+
})
112+
} else {
113+
None
103114
}
104-
_ => None,
105115
})
106116
.or(infer::get(&self.body)
107117
.map(|kind| MediaType::from_str(kind.mime_type()).ok())

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/src/lib.rs

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,24 @@ fn hopp_auth_port() -> u16 {
1818

1919
#[cfg_attr(mobile, tauri::mobile_entry_point)]
2020
pub fn run() {
21-
tracing::info!("Starting Hoppscotch Desktop v{}", env!("CARGO_PKG_VERSION"));
22-
23-
let server_port = portpicker::pick_unused_port().expect("Cannot find unused port");
24-
SERVER_PORT
25-
.set(server_port)
26-
.expect("Failed to set server port");
27-
tracing::info!("Selected server port: {}", server_port);
28-
2921
tauri::Builder::default()
30-
.plugin(
31-
tauri_plugin_window_state::Builder::new()
32-
.with_state_flags(
33-
StateFlags::SIZE
34-
| StateFlags::POSITION
35-
| StateFlags::MAXIMIZED
36-
| StateFlags::FULLSCREEN,
37-
)
38-
.with_denylist(&["main"])
39-
.build(),
40-
)
41-
.plugin(tauri_plugin_process::init())
42-
.plugin(tauri_plugin_updater::Builder::new().build())
43-
.plugin(tauri_plugin_store::Builder::new().build())
44-
.plugin(tauri_plugin_deep_link::init())
45-
.plugin(tauri_plugin_dialog::init())
4622
.setup(|app| {
4723
let handle = app.handle().clone();
48-
tracing::info!(app_name = %app.package_info().name, "Configuring deep link handler");
4924

25+
logger::setup(app.handle().clone())?;
26+
tracing::info!("Logger setup complete");
27+
28+
let server_port = portpicker::pick_unused_port().expect("Cannot find unused port");
29+
tracing::info!("Selected server port: {}", server_port);
30+
SERVER_PORT
31+
.set(server_port)
32+
.expect("Failed to set server port");
33+
let port = *SERVER_PORT.get().expect("Server port not initialized");
34+
tracing::info!(port = port, "Initializing server with pre-selected port");
35+
let port = server::init(port, handle.clone());
36+
tracing::info!(port = port, "Server initialization complete");
37+
38+
tracing::info!(app_name = %app.package_info().name, "Configuring deep link handler");
5039
app.deep_link().on_open_url(move |event| {
5140
let urls = event.urls();
5241
tracing::info!(
@@ -64,24 +53,29 @@ pub fn run() {
6453
);
6554
});
6655
});
67-
Ok(())
68-
})
69-
.setup(|app| {
70-
let handle = app.handle().clone();
7156

72-
let port = *SERVER_PORT.get().expect("Server port not initialized");
73-
tracing::info!(port = port, "Initializing server with pre-selected port");
74-
let port = server::init(port, handle);
75-
tracing::info!(port = port, "Server initialization complete");
57+
tracing::info!("Starting Hoppscotch Desktop v{}", env!("CARGO_PKG_VERSION"));
58+
7659
Ok(())
7760
})
61+
.plugin(
62+
tauri_plugin_window_state::Builder::new()
63+
.with_state_flags(
64+
StateFlags::SIZE
65+
| StateFlags::POSITION
66+
| StateFlags::MAXIMIZED
67+
| StateFlags::FULLSCREEN,
68+
)
69+
.with_denylist(&["main"])
70+
.build(),
71+
)
72+
.plugin(tauri_plugin_process::init())
73+
.plugin(tauri_plugin_updater::Builder::new().build())
74+
.plugin(tauri_plugin_store::Builder::new().build())
75+
.plugin(tauri_plugin_deep_link::init())
76+
.plugin(tauri_plugin_dialog::init())
7877
.plugin(tauri_plugin_shell::init())
7978
.plugin(tauri_plugin_fs::init())
80-
.setup(|app| {
81-
logger::setup(app.handle().clone())?;
82-
tracing::info!("Logger setup complete");
83-
Ok(())
84-
})
8579
.plugin(tauri_plugin_appload::init(
8680
VendorConfigBuilder::new().bundle(
8781
include_bytes!("../../bundle.zip").to_vec(),

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)