fix(relay): better matching for content-type detection (#5025)

This commit is contained in:
Shreyas 2025-04-29 13:10:08 +05:30 committed by GitHub
parent decbb56c9f
commit 8c6ec87f90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 72 additions and 68 deletions

View file

@ -1,7 +1,7 @@
{
"name": "hoppscotch-agent",
"private": true,
"version": "0.1.9",
"version": "0.1.10",
"type": "module",
"scripts": {
"dev": "vite",

View file

@ -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",

View file

@ -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"

View file

@ -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",

View file

@ -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",

View file

@ -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())

View file

@ -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",

View file

@ -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",

View file

@ -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(),

View file

@ -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.1
version: 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/quick-lru@5.2.0':
@ -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