HTTP Headers
2.1.0
A header defined in the configuration gets sent along the responses to the webview.
This doesn’t include IPC messages and error responses.
To be more specific, every response sent via the get_response
function in
crates/tauri/src/protocol/tauri.rs ↗
will include those headers.
Header Names
The header names are limited to:
- Access-Control-Allow-Credentials ↗
- Access-Control-Allow-Headers ↗
- Access-Control-Allow-Methods ↗
- Access-Control-Expose-Headers ↗
- Access-Control-Max-Age ↗
- Cross-Origin-Embedder-Policy ↗
- Cross-Origin-Opener-Policy ↗
- Cross-Origin-Resource-Policy ↗
- Permissions-Policy ↗
- Timing-Allow-Origin ↗
- X-Content-Type-Options ↗
- Tauri-Custom-Header
How to Configure Headers
- with a string
- with an Array of strings
- with an Object/Key-Value, where the values must be strings
- with null
The header values are always converted to strings for the actual response. Depending, on how the configuration file looks, some header values need to be composed. Those are the rules on how a composite gets created:
string
: stays the same for the resulting header valueArray
: items are joined by,
for the resulting header valuekey-value
: items are composed from: key + space + value. Items are then joined by;
for the resulting header valuenull
: header will be ignored
Example
In this example Cross-Origin-Opener-Policy
and Cross-Origin-Embedder-Policy
are set to
allow for the use of SharedArrayBuffer ↗
.
Timing-Allow-Origin
grants scripts loaded from the listed websites to access detailed network timing data via the Resource Timing API ↗.
For the helloworld example, this config results in:
Frameworks
Some development environments require extra settings, to emulate the production environment.
JavaScript/TypeScript
For setups running the build tool Vite (those include Qwik, React, Solid, Svelte, and Vue) add the wanted headers to vite.config.ts
.
Sometimes the vite.config.ts
is integrated into the frameworks configuration file, but the setup stays the same.
In case of Angular add them to angular.json
.
And in case of Nuxt to nuxt.config.ts
.
Next.js doesn’t rely on Vite, so the approach is different.
Read more about it here ↗.
The headers are defined in next.config.js
.
Rust
For Yew and Leptos add the headers to Trunk.toml
© 2024 Tauri Contributors. CC-BY / MIT