[bug] The http plugin cannot send requests using the ip:port format
Describe the bug
Tauri info output
└─(22:22:13)──> npm run tauri info 1 ↵ ──(二, 618)─┘
> [email protected] tauri
> tauri info
[✔] Environment
- OS: Mac OS 14.5.0 X64
✔ Xcode Command Line Tools: installed
✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
✔ Rust toolchain: stable-aarch64-apple-darwin (default)
- node: 21.7.1
- npm: 10.7.0
[-] Packages
- tauri [RUST]: 2.0.0-beta.22
- tauri-build [RUST]: 2.0.0-beta.17
- wry [RUST]: 0.40.1
- tao [RUST]: 0.28.1
- tauri-cli [RUST]: 1.5.11
- @tauri-apps/api [NPM]: 2.0.0-beta.13
- @tauri-apps/cli [NPM]: 2.0.0-beta.20
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist
- devUrl: http://localhost:1420/
- framework: React
- bundler: Vite
src-tauri/capabilities/default.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"path:default",
"event:default",
"window:default",
"app:default",
"image:default",
"resources:default",
"menu:default",
"tray:default",
"shell:allow-open",
{
"identifier": "http:default",
"allow": [
{"url": "http://127.0.0.1:24666"}
]
}
]
}
When i use ApiFox
When i use http plugin
import React, { useState } from 'react';
import { fetch } from '@tauri-apps/plugin-http';
...
try {
const response = await fetch('http://127.0.0.1:24666/ai/ocr/general', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
});
console.log('res_t'+response.status);
const data = await response.json();
setResult(data);
} catch (error) {
console.error('Error:', error);
}
...
And default fetch
import React, { useState } from 'react';
...
try {
const response = await fetch('http://127.0.0.1:24666/ai/ocr/general', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
});
console.log('res_t'+response.status);
const data = await response.json();
setResult(data);
} catch (error) {
console.error('Error:', error);
}
...
Reproduction
No response
Expected behavior
No response
Full tauri info output
Des
Stack trace
No response
Additional context
No response
I'm also affected. My issue lies within https handling rather than http, but the symptoms are the same
> [email protected] tauri
> tauri info
[✔] Environment
- OS: Windows 10.0.22631 X64
✔ WebView2: 113.0.1774.50
✔ MSVC: Visual Studio Community 2022
✔ rustc: 1.79.0 (129f3b996 2024-06-10)
✔ cargo: 1.79.0 (ffa9cf99a 2024-06-03)
✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
- node: 20.11.0
- pnpm: 8.10.0
- yarn: 1.22.19
- npm: 9.8.0
[-] Packages
- tauri [RUST]: 2.0.0-beta.23
- tauri-build [RUST]: 2.0.0-beta.18
- wry [RUST]: 0.41.0
- tao [RUST]: 0.28.1
- @tauri-apps/api : not installed!
- @tauri-apps/cli [NPM]: 2.0.0-beta.20
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../src
- Note, "Windows 10" is misleading as that's the version of Windows 11.
For now adding stuff into etc/hosts helps to circumvent the need of IP addresses, but it's not really a solution for mobile apps
Edit4:
Did more digging.
[2024-07-07][08:03:46][hyper_util::client::legacy::pool][TRACE] checkout waiting for idle connection: ("https", 192.168.1.113:8443)
[2024-07-07][08:03:46][reqwest::connect][DEBUG] starting new connection: https://192.168.1.113:8443/
[2024-07-07][08:03:46][hyper_util::client::legacy::connect::http][TRACE] Http::connect; scheme=Some("https"), host=Some("192.168.1.113"), port=Some(Port(8443))
[2024-07-07][08:03:46][hyper_util::client::legacy::connect::http][DEBUG] connecting to 192.168.1.113:8443
[2024-07-07][08:03:46][hyper_util::client::legacy::connect::http][DEBUG] connected to 192.168.1.113:8443
[2024-07-07][08:03:46][hyper_util::client::legacy::pool][TRACE] checkout dropped for ("https", 192.168.1.113:8443)
It doesn't help that neither print! nor debug! output anything to stdout, as I've still no idea what's happening and how exactly I once manages to at least get http working.
The more I dig into this, the more things break. Previously I could use a debugging proxy to see the requests. But now whenever I set up the proxy object inside my init, I'm getting the same 400 error as with pi:port on any address.
If, however, I use hosts to assign a domain for the address and than use that address, then I'm getting this additional line in the log
[2024-07-07][09:00:35][hyper_util::client::legacy::client][TRACE] http1 handshake complete, spawning background dispatcher task
这是来自动回复邮件。你好,我将在稍后尽快给你回复。
I couldn't reproduce these issues at all, please make a minimal reproducible example and I will take a look
> npm create tauri-app@latest -- --beta
✔ Project name · test
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun)
✔ Choose your package manager · npm
✔ Choose your UI template · Vanilla
✔ Choose your UI flavor · JavaScript
✔ Would you like to setup the project for mobile as well? · yes
Template created! To get started run:
cd test
npm install
npm run tauri android init
For Desktop development, run:
npm run tauri dev
For Android development, run:
npm run tauri android dev
> cd test
> npm install
> npm run tauri add http
[email protected] tauri
tauri add http
Info Installing Cargo dependency "tauri-plugin-http"...
Updating crates.io index
Adding tauri-plugin-http v2.0.0-beta.11 to dependencies
Features:
+ charset
+ cookies
+ http2
+ macos-system-configuration
+ rustls-tls
- blocking
- brotli
- deflate
- gzip
- json
- multipart
- native-tls
- native-tls-alpn
- native-tls-vendored
- rustls-tls-manual-roots
- rustls-tls-native-roots
- rustls-tls-webpki-roots
- socks
- stream
- trust-dns
- unsafe-headers
Updating crates.io index
Locking 451 packages to latest compatible versions
Adding addr2line v0.22.0 (latest: v0.23.0)
Adding base64 v0.21.7 (latest: v0.22.1)
Adding bitflags v1.3.2 (latest: v2.6.0)
Adding brotli v3.5.0 (latest: v6.0.0)
Adding brotli-decompressor v2.5.1 (latest: v4.0.1)
Adding cairo-rs v0.18.5 (latest: v0.20.0)
Adding cairo-sys-rs v0.18.2 (latest: v0.20.0)
Adding cargo_toml v0.17.2 (latest: v0.20.3)
Adding cfb v0.7.3 (latest: v0.10.0)
Adding convert_case v0.4.0 (latest: v0.6.0)
Adding cssparser v0.27.2 (latest: v0.34.0)
Adding gdk-pixbuf v0.18.5 (latest: v0.20.0)
Adding gdk-pixbuf-sys v0.18.0 (latest: v0.20.0)
Adding generator v0.7.5 (latest: v0.8.1)
Adding generic-array v0.14.7 (latest: v1.1.0)
Adding getrandom v0.1.16 (latest: v0.2.15)
Adding gimli v0.29.0 (latest: v0.30.0)
Adding gio v0.18.4 (latest: v0.20.0)
Adding gio-sys v0.18.1 (latest: v0.20.0)
Adding glib v0.18.5 (latest: v0.20.0)
Adding glib-macros v0.18.5 (latest: v0.20.0)
Adding glib-sys v0.18.1 (latest: v0.20.0)
Adding gobject-sys v0.18.0 (latest: v0.20.0)
Adding hashbrown v0.12.3 (latest: v0.14.5)
Adding heck v0.4.1 (latest: v0.5.0)
Adding hermit-abi v0.3.9 (latest: v0.4.0)
Adding html5ever v0.26.0 (latest: v0.27.0)
Adding idna v0.3.0 (latest: v1.0.2)
Adding idna v0.5.0 (latest: v1.0.2)
Adding indexmap v1.9.3 (latest: v2.2.6)
Adding infer v0.15.0 (latest: v0.16.0)
Adding itoa v0.4.8 (latest: v1.0.11)
Adding jni-sys v0.3.0 (latest: v0.4.0)
Adding json-patch v1.4.0 (latest: v2.0.0)
Adding libloading v0.7.4 (latest: v0.8.4)
Adding loom v0.5.6 (latest: v0.7.2)
Adding malloc_buf v0.0.6 (latest: v1.0.0)
Adding markup5ever v0.11.0 (latest: v0.12.1)
Adding matchers v0.1.0 (latest: v0.2.0)
Adding mio v0.8.11 (latest: v1.0.0)
Adding ndk v0.7.0 (latest: v0.9.0)
Adding ndk-sys v0.4.1+23.1.7779620 (latest: v0.6.0+11769913)
Adding nu-ansi-term v0.46.0 (latest: v0.50.0)
Adding num_enum v0.5.11 (latest: v0.7.2)
Adding num_enum_derive v0.5.11 (latest: v0.7.2)
Adding pango v0.18.3 (latest: v0.20.0)
Adding pango-sys v0.18.0 (latest: v0.20.0)
Adding phf v0.8.0 (latest: v0.11.2)
Adding phf v0.10.1 (latest: v0.11.2)
Adding phf_codegen v0.8.0 (latest: v0.11.2)
Adding phf_codegen v0.10.0 (latest: v0.11.2)
Adding phf_generator v0.8.0 (latest: v0.11.2)
Adding phf_generator v0.10.0 (latest: v0.11.2)
Adding phf_macros v0.8.0 (latest: v0.11.2)
Adding phf_shared v0.8.0 (latest: v0.11.2)
Adding phf_shared v0.10.0 (latest: v0.11.2)
Adding proc-macro-crate v1.3.1 (latest: v3.1.0)
Adding proc-macro-crate v2.0.2 (latest: v3.1.0)
Adding quick-xml v0.32.0 (latest: v0.36.0)
Adding rand v0.7.3 (latest: v0.8.5)
Adding rand_chacha v0.2.2 (latest: v0.3.1)
Adding rand_core v0.5.1 (latest: v0.6.4)
Adding rand_hc v0.2.0 (latest: v0.3.2)
Adding rand_pcg v0.2.1 (latest: v0.3.1)
Adding raw-window-handle v0.5.2 (latest: v0.6.2)
Adding regex-automata v0.1.10 (latest: v0.4.7)
Adding regex-syntax v0.6.29 (latest: v0.8.4)
Adding rustc-hash v1.1.0 (latest: v2.0.0)
Adding selectors v0.22.0 (latest: v0.25.0)
Adding servo_arc v0.1.1 (latest: v0.3.0)
Adding siphasher v0.3.11 (latest: v1.0.1)
Adding soup3 v0.5.0 (latest: v0.6.0)
Adding soup3-sys v0.5.0 (latest: v0.6.0)
Adding syn v1.0.109 (latest: v2.0.70)
Adding system-configuration v0.5.1 (latest: v0.6.0)
Adding system-configuration-sys v0.5.0 (latest: v0.6.0)
Adding system-deps v6.2.2 (latest: v7.0.1)
Adding toml v0.7.8 (latest: v0.8.14)
Adding toml v0.8.2 (latest: v0.8.14)
Adding toml_datetime v0.6.3 (latest: v0.6.6)
Adding toml_edit v0.19.15 (latest: v0.22.15)
Adding toml_edit v0.20.2 (latest: v0.22.15)
Adding wasi v0.9.0+wasi-snapshot-preview1 (latest: v0.13.1+wasi-0.2.0)
Adding wasi v0.11.0+wasi-snapshot-preview1 (latest: v0.13.1+wasi-0.2.0)
Adding windows v0.48.0 (latest: v0.58.0)
Adding windows v0.57.0 (latest: v0.58.0)
Adding windows-core v0.52.0 (latest: v0.58.0)
Adding windows-core v0.57.0 (latest: v0.58.0)
Adding windows-implement v0.57.0 (latest: v0.58.0)
Adding windows-interface v0.57.0 (latest: v0.58.0)
Adding windows-result v0.1.2 (latest: v0.2.0)
Adding windows-sys v0.45.0 (latest: v0.52.0)
Adding windows-sys v0.48.0 (latest: v0.52.0)
Adding windows-targets v0.42.2 (latest: v0.52.6)
Adding windows-targets v0.48.5 (latest: v0.52.6)
Adding windows_aarch64_gnullvm v0.42.2 (latest: v0.52.6)
Adding windows_aarch64_gnullvm v0.48.5 (latest: v0.52.6)
Adding windows_aarch64_msvc v0.42.2 (latest: v0.52.6)
Adding windows_aarch64_msvc v0.48.5 (latest: v0.52.6)
Adding windows_i686_gnu v0.42.2 (latest: v0.52.6)
Adding windows_i686_gnu v0.48.5 (latest: v0.52.6)
Adding windows_i686_msvc v0.42.2 (latest: v0.52.6)
Adding windows_i686_msvc v0.48.5 (latest: v0.52.6)
Adding windows_x86_64_gnu v0.42.2 (latest: v0.52.6)
Adding windows_x86_64_gnu v0.48.5 (latest: v0.52.6)
Adding windows_x86_64_gnullvm v0.42.2 (latest: v0.52.6)
Adding windows_x86_64_gnullvm v0.48.5 (latest: v0.52.6)
Adding windows_x86_64_msvc v0.42.2 (latest: v0.52.6)
Adding windows_x86_64_msvc v0.48.5 (latest: v0.52.6)
Adding winnow v0.5.40 (latest: v0.6.13)
Info Installing NPM dependency "@tauri-apps/plugin-http"...
added 2 packages, and audited 5 packages in 2s
2 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Added permission `http:default` to `default` at F:\Projects\Tauri\test\src-tauri\capabilities\default.json
Info Adding plugin to F:\Projects\Tauri\test\src-tauri\src/lib.rs
Info Running `cargo fmt`...
PS F:\Projects\Tauri\test>
In F:\Projects\Tauri\test\src\main.js:
const { invoke } = window.__TAURI__.core;
let greetInputEl;
let greetMsgEl;
async function greet() {
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
greetMsgEl.textContent = await invoke("greet", { name: greetInputEl.value });
}
window.addEventListener("DOMContentLoaded", () => {
greetInputEl = document.querySelector("#greet-input");
greetMsgEl = document.querySelector("#greet-msg");
document.querySelector("#greet-form").addEventListener("submit", (e) => {
e.preventDefault();
greet();
});
});
async function run() {
let fetch2 = window.__TAURI__.http.fetch
try {
console.log("fetching", fetch2)
let result = await fetch2("http://192.168.1.113:8443/")
console.log(result)
} catch(err) {
console.log(err)
}
}
await run()
In src-tauri\capabilities\default.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": [
"main"
],
"permissions": [
"path:default",
"event:default",
"window:default",
"app:default",
"image:default",
"resources:default",
"menu:default",
"tray:default",
"shell:allow-open",
"http:default",
{
"identifier": "http:default",
"allow": [
{
"url": "http://**"
},
{
"url": "https://**"
},
{
"url": "http://*:*"
},
{
"url": "https://*:*"
}
]
}
]
}
Then run tauri
> npm run tauri dev
> [email protected] tauri
> tauri dev
Info Watching F:\Projects\Tauri\test\src-tauri for changes...
Compiling serde v1.0.204
Compiling cssparser v0.27.2
Compiling html5ever v0.26.0
Compiling serde_with_macros v3.8.3
Compiling phf v0.11.2
Compiling schemars_derive v0.8.21
Compiling infer v0.15.0
Compiling anyhow v1.0.86
Compiling version_check v0.9.4
Compiling pin-project-lite v0.2.14
Compiling libc v0.2.155
Compiling vswhom-sys v0.1.2
Compiling windows-sys v0.48.0
Compiling getrandom v0.2.15
Compiling option-ext v0.2.0
Compiling mio v0.8.11
Compiling socket2 v0.5.7
Compiling unicode-normalization v0.1.23
Compiling slab v0.4.9
Compiling selectors v0.22.0
Compiling num_cpus v1.16.0
Compiling unicode-bidi v0.3.15
Compiling futures-core v0.3.30
Compiling serde_json v1.0.120
Compiling parking_lot_core v0.9.10
Compiling heck v0.5.0
Compiling vswhom v0.1.0
Compiling typenum v1.17.0
Compiling parking_lot v0.12.3
Compiling idna v0.5.0
Compiling generic-array v0.14.7
Compiling ring v0.17.8
Compiling windows-interface v0.57.0
Compiling windows-implement v0.57.0
Compiling windows-result v0.1.2
Compiling futures-macro v0.3.30
Compiling futures-task v0.3.30
Compiling pin-utils v0.1.0
Compiling tracing-core v0.1.32
Compiling futures-sink v0.3.30
Compiling httparse v1.9.4
Compiling serde_spanned v0.6.6
Compiling toml_datetime v0.6.3
Compiling semver v1.0.23
Compiling string_cache v0.8.7
Compiling toml_edit v0.20.2
Compiling markup5ever v0.11.0
Compiling bytes v1.6.0
Compiling indexmap v1.9.3
Compiling url v2.5.2
Compiling cargo-platform v0.1.8
Compiling camino v1.1.7
Compiling erased-serde v0.4.5
Compiling serde_with v3.8.3
Compiling http v1.1.0
Compiling tokio v1.38.0
Compiling schemars v0.8.21
Compiling urlpattern v0.2.0
Compiling json-patch v1.4.0
Compiling serde-untagged v0.1.6
Compiling cargo_metadata v0.18.1
Compiling rustc_version v0.4.0
Compiling toml v0.8.2
Compiling kuchikiki v0.8.2
Compiling toml_edit v0.19.15
Compiling cargo_toml v0.17.2
Compiling tauri-utils v2.0.0-beta.18
Compiling winreg v0.52.0
Compiling dirs-sys v0.4.1
Compiling dirs v5.0.1
Compiling embed-resource v2.4.2
Compiling futures-util v0.3.30
Compiling windows-core v0.57.0
Compiling rustls-pki-types v1.7.0
Compiling simd-adler32 v0.3.7
Compiling toml v0.7.8
Compiling http-body v1.0.0
Compiling windows v0.57.0
Compiling tauri-winres v0.1.1
Compiling tokio-util v0.7.11
Compiling tracing v0.1.40
Compiling pin-project-internal v1.1.5
Compiling raw-window-handle v0.6.2
Compiling crossbeam-utils v0.8.20
Compiling spin v0.9.8
Compiling adler v1.0.2
Compiling atomic-waker v1.1.2
Compiling try-lock v0.2.5
Compiling untrusted v0.9.0
Compiling want v0.3.1
Compiling h2 v0.4.5
Compiling miniz_oxide v0.7.4
Compiling dpi v0.1.1
Compiling tauri-build v2.0.0-beta.18
Compiling tauri-plugin v2.0.0-beta.18
Compiling futures-channel v0.3.30
Compiling uuid v1.10.0
Compiling pin-project v1.1.5
Compiling winapi-util v0.1.8
Compiling webview2-com-sys v0.31.0
Compiling crc32fast v1.4.2
Compiling tower-layer v0.3.2
Compiling native-tls v0.2.12
Compiling rustls v0.23.11
Compiling time-core v0.1.2
Compiling powerfmt v0.2.0
Compiling tower-service v0.3.2
Compiling num-conv v0.1.0
Compiling tower v0.4.13
Compiling deranged v0.3.11
Compiling time-macros v0.2.18
Compiling flate2 v1.0.30
Compiling same-file v1.0.6
Compiling cfb v0.7.3
Compiling hyper v1.4.1
Compiling rustls-webpki v0.102.5
Compiling crypto-common v0.1.6
Compiling block-buffer v0.10.4
Compiling fdeflate v0.3.4
Compiling bitflags v2.6.0
Compiling cookie v0.18.1
Compiling schannel v0.1.23
Compiling windows-version v0.1.1
Compiling unicode-segmentation v1.11.0
Compiling zeroize v1.8.1
Compiling subtle v2.6.1
Compiling base64 v0.22.1
Compiling cfg_aliases v0.2.1
Compiling softbuffer v0.4.5
Compiling time v0.3.36
Compiling png v0.17.13
Compiling crossbeam-channel v0.5.13
Compiling digest v0.10.7
Compiling hyper-util v0.1.6
Compiling walkdir v2.5.0
Compiling idna v0.3.0
Compiling webview2-com-macros v0.7.0
Compiling tauri-runtime v2.0.0-beta.19
Compiling psl-types v2.0.11
Compiling cpufeatures v0.2.12
Compiling wry v0.41.0
Compiling sha2 v0.10.8
Compiling publicsuffix v2.2.3
Compiling ico v0.3.0
Compiling tokio-native-tls v0.3.1
Compiling http-body-util v0.1.2
Compiling webpki-roots v0.26.3
Compiling instant v0.1.13
Compiling tokio-rustls v0.26.0
Compiling lazy_static v1.5.0
Compiling tauri-runtime-wry v2.0.0-beta.19
Compiling hyper-tls v0.6.0
Compiling tauri-codegen v2.0.0-beta.18
Compiling hyper-rustls v0.27.2
Compiling cookie_store v0.21.0
Compiling keyboard-types v0.7.0
Compiling rustls-pemfile v2.1.2
Compiling serde_urlencoded v0.7.1
Compiling serialize-to-javascript-impl v0.1.1
Compiling encoding_rs v0.8.34
Compiling ipnet v2.9.0
Compiling sync_wrapper v1.0.1
Compiling mime v0.3.17
Compiling muda v0.13.5
Compiling serialize-to-javascript v0.1.1
Compiling window-vibrancy v0.5.0
Compiling serde_repr v0.1.19
Compiling state v0.6.0
Compiling winapi v0.3.9
Compiling os_pipe v1.2.0
Compiling open v5.3.0
Compiling data-url v0.3.1
Compiling reqwest v0.12.5
Compiling tauri v2.0.0-beta.23
Compiling tauri-plugin-fs v2.0.0-beta.10
Compiling tauri-macros v2.0.0-beta.18
Compiling tauri-plugin-http v2.0.0-beta.11
Compiling tauri-plugin-shell v2.0.0-beta.8
Compiling shared_child v1.0.0
Compiling test v0.0.0 (F:\Projects\Tauri\test\src-tauri)
Compiling tao v0.28.1
Compiling webview2-com v0.31.0
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 30s
When ran, ctrl+shift+i to open devtools and see this:
Attached project files to look at test.zip
On a side note, it doesn't help that on literally any error the IPC responds with
error sending request for url (<insert url here>)
I never know whether the server is unreachable or whether it's a certificate's issue (in case of https) or anything else, really. Is there a way to receive more clear responses in case of a failure?
Error: "url not allowed on the configured scope: http://localhost:8787/v1/models"
这是来自动回复邮件。你好,我将在稍后尽快给你回复。
Does anyone still face this issue with stable versions?
I had to test urls with ports for another discussion and it worked fine for me.
Does anyone still face this issue with stable versions?
I had to test urls with ports for another discussion and it worked fine for me.
At least when I used it yesterday, I could use the URL in the ip:port format.
^If anyone is still running into this issue, I was able to fix it to work with all URLs by expanding the allow list to include the ip:port format, like so:
{
"identifier": "http:default",
"allow": [
{
"url": "http://*"
},
{
"url": "https://*"
},
{
"url": "http://*:*"
},
{
"url": "https://*:*"
}
]
},
Credits to https://github.com/tauri-apps/plugins-workspace/issues/2131 for the solution.