new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Tauri · Plugins and security · all subjects

http

16 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Upload file to remote server API

The `upload()` function takes four parameters: a URL string for the remote server, a file path string for the local file to upload, a progress callback function that receives an object with `progress` and `total` properties (both in bytes), and optional headers object. The progress callback will be called as the upload progresses.

Download file from remote server API

The `download()` function takes four parameters: a URL string for the remote file to download, a file path string where to save the file locally, a progress callback function that receives an object with `progress` and `total` properties (both in bytes), and optional headers object. The progress callback will be called as the download progresses.

Download plugin example code

Example of downloading a file using the upload plugin: `import { download } from '@tauri-apps/plugin-upload'; download('https://example.com/file-download-link', './path/to/save/my/file.txt', ({ progress, total }) => console.log(\`Downloaded \${progress} of \${total} bytes\`), { 'Content-Type': 'text/plain' });`

HTTP headers feature availability

HTTP headers configuration in Tauri is available since version 2.1.0.

HTTP headers configuration value types

HTTP header values in tauri.conf.json can be configured as: a string (stays the same in the resulting header value), an array of strings (items joined by ', ' in the resulting header value), an object/key-value with string values (items composed as key + space + value, then joined by '; ' in the resulting header value), or null (header will be ignored).

HTTP headers configuration location

HTTP headers are configured in tauri.conf.json under the path: app.security.headers. The Content-Security-Policy (CSP) is not defined in the headers section but separately under app.security.csp.

HTTP headers example configuration

Example HTTP headers configuration in src-tauri/tauri.conf.json: { "app": { "security": { "headers": { "Cross-Origin-Opener-Policy": "same-origin", "Cross-Origin-Embedder-Policy": "require-corp", "Timing-Allow-Origin": [ "https://developer.mozilla.org", "https://example.com" ], "X-Content-Type-Options": null, "Access-Control-Expose-Headers": "Tauri-Custom-Header", "Tauri-Custom-Header": { "key1": "'value1' 'value2'", "key2": "'value3'" } }, "csp": "default-src 'self'; connect-src ipc: http://ipc.localhost" } } }

HTTP headers example resulting output

The example configuration results in the following HTTP headers being sent: access-control-allow-origin: http://tauri.localhost access-control-expose-headers: Tauri-Custom-Header content-security-policy: default-src 'self'; connect-src ipc: http://ipc.localhost; script-src 'self' 'sha256-Wjjrs6qinmnr+tOry8x8PPwI77eGpUFR3EEGZktjJNs=' content-type: text/html cross-origin-embedder-policy: require-corp cross-origin-opener-policy: same-origin tauri-custom-header: key1 'value1' 'value2'; key2 'value3' timing-allow-origin: https://developer.mozilla.org, https://example.com

HTTP headers framework configuration

For development environments to properly emulate production, HTTP headers may need to be defined in both the framework's configuration (for development mode) and the Tauri config (for build mode). Frameworks won't include headers defined in their config files at build time, and Tauri can only inject headers to the final build output, not to the framework's dev server.

HTTP headers Next.js configuration

For Next.js, add headers to next.config.js using the async headers() function: ```javascript module.exports = { async headers() { return [ { source: '/*', headers: [ { key: 'Cross-Origin-Opener-Policy', value: 'same-origin', }, { key: 'Cross-Origin-Embedder-Policy', value: 'require-corp', }, { key: 'Timing-Allow-Origin', value: 'https://developer.mozilla.org, https://example.com', }, { key: 'Access-Control-Expose-Headers', value: 'Tauri-Custom-Header', }, { key: 'Tauri-Custom-Header', value: "key1 'value1' 'value2'; key2 'value3'", }, ], }, ] }, } ```

Tauri-Custom-Header testing note

When using Tauri-Custom-Header for tests, remember to set Access-Control-Expose-Headers accordingly.

HTTP plugin setup in Rust

To use tauri-plugin-http: Add tauri-plugin-http = "2" to Cargo.toml. In main(): plugin(tauri_plugin_http::init()). In setup: use tauri_plugin_http::reqwest; then use async_runtime: let response = reqwest::get(url).await?; response.text().await

HTTP plugin setup in JavaScript

To use @tauri-apps/plugin-http: Add @tauri-apps/plugin-http: ^2.0.0 to package.json. In Rust: plugin(tauri_plugin_http::init()). In JavaScript: import { fetch } from '@tauri-apps/plugin-http'; const response = await fetch('https://url');

HTTP plugin reexports reqwest

The tauri-plugin-http Rust plugin reexports reqwest, allowing you to consult reqwest documentation for additional information.

HTTP plugin re-exports reqwest in Rust

The HTTP plugin re-exports the reqwest crate for use in Rust code: use tauri_plugin_http::reqwest;

HTTP plugin setup and API in Tauri 2.0

Add 'tauri-plugin-http = "2"' to Cargo.toml. Register with 'tauri::Builder::default().plugin(tauri_plugin_http::init())'. In JavaScript, import { fetch } from '@tauri-apps/plugin-http'; const response = await fetch('https://raw.githubusercontent.com/tauri-apps/tauri/dev/package.json');

Give your agent this brain