api-client/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-relay
Shreyas 72ff950d91
fix(relay): avoid override with header passthrough (#4931)
The current implementation causes duplicate `Content-Type` headers when users
override headers in the UI or use OAuth2 authentication with the agent.
Web servers receive multiple `Content-Type` headers which causes
undefined behavior and 400 errors for backends that don't accept duplicate headers.

This also fixes inconsistent behavior when overriding the `Content-Type` header
with custom values (e.g., `application/json;v=2`).

While HTTP/1.1 headers are case-insensitive per RFC 7230, inconsistent handling
across server implementations can treat differently-cased variations (e.g.,
"Content-Type" vs "content-type") as distinct headers. HTTP/2 (RFC 7540) mandates
converting all header field names to lowercase, which would prevent this issue.

This patch removes the automatic content-type header insertion, allowing user-defined
headers to take precedence without duplication. The is a temporary
workaround until we implement a HTTP/2-compliant solution with proper normalization.

This was implemented initially to support moving lower level handling
towards the kernel, although since the larger refactor has been slightly
deferred in favor of stability, this change is suitable for current
state.

This will be revisited when we implement HTTP/2 compliant header handling in the
kernel layer as part of our upcoming kernel efforts.

Use the following request to test this out on Desktop app and Agent and
override `Content-Type` header to `application/json;=v2`:

```
curl --request POST \
  --url 'https://echo.qubit.codes/?qp=1' \
  --header 'Content-Type: application/json;v=2' \
  --data '{ "test-key": "test-value" }'
```
2025-03-25 16:34:27 +05:30
..
dist-js fix: enable aws auth passthrough (#4825) 2025-03-05 18:31:59 +05:30
guest-js fix: enable aws auth passthrough (#4825) 2025-03-05 18:31:59 +05:30
permissions feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
src feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
.envrc feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
.gitignore feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
build.rs feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
Cargo.lock fix(relay): avoid override with header passthrough (#4931) 2025-03-25 16:34:27 +05:30
Cargo.toml feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
devenv.lock feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
devenv.nix feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
devenv.yaml feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
LICENSE.md feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
package.json feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
pnpm-lock.yaml feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
README.md feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
rollup.config.js feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30
tsconfig.json feat: platform independent core and the new desktop app (#4684) 2025-02-28 00:01:25 +05:30

Tauri Plugin: Relay

A HTTP request-response relay plugin for Tauri apps, providing advanced request handling capabilities including custom headers, certificates, proxies, and local system integration.

GitHub License MIT Tauri 2.0 Rust

Features

  • 🦀 Blazingly fast!
  • HTTP client built on libcurl
  • Security with SSL/TLS certificate management
  • Proxy support
  • Multiple authentication methods (Basic, Bearer, Digest)
  • Content handling (JSON, Form Data, Binary)
  • Async request execution with cancellation support

Installation

Important

This plugin requires Tauri 2.0 or later.

Add the plugin to your project by installing directly from GitHub:

[dependencies]
tauri-plugin-relay = { git = "https://github.com/CuriousCorrelation/tauri-plugin-relay" }
"dependencies": {
  "@CuriousCorrelation/plugin-relay": "github:CuriousCorrelation/tauri-plugin-relay"
}

Quick Start

Rust

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_relay::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

JavaScript/TypeScript

import { execute, cancel } from '@CuriousCorrelation/plugin-relay'

// Execute a request
const result = await execute({
  id: 1,
  url: "https://api.example.com/data",
  method: "POST",
  headers: {
    "Content-Type": ["application/json"]
  },
  content: {
    kind: "json",
    content: { hello: "world" }
  }
})

// Cancel a request
await cancel(1)

Content Types

The plugin supports multiple content types for requests:

Type Description
text Plain text content
json JSON data with automatic parsing
form Multipart form data with file support
binary Raw binary data with optional MIME type
urlencoded URL-encoded form data

Authentication

Built-in support for various authentication methods:

Method Description
basic Basic HTTP authentication
bearer Bearer token authentication
digest Digest authentication (MD5, SHA-256, SHA-512)

Security

The plugin provides extensive security options:

  • Client certificate support (PEM, PKCS#12)
  • Custom CA certificates
  • Certificate validation control
  • Host verification settings

Development

Requirements:

  • Rust 1.77.2 or later
  • Node.js 18 or later
  • pnpm
  • libcurl with SSL support

Error Handling

The plugin provides detailed error information for:

  • Network failures
  • Certificate issues
  • Timeout scenarios
  • Parse errors
  • Request cancellations

License

Code: (c) 2024 - CuriousCorrelation

MIT or MIT/Apache 2.0 where applicable.