Skip to content

[http][v2] request header sent without Content-Type #1349

Description

@LIznzn

Describe the bug

When fetch() is used to pass multipart/form-data to the remote server, the remote server cannot parse the data because the header lacks Content-Type.

Although mentioned in the official documentation, fetch() will provide the same function as the Fetch Web API. But it now seems to lack header processing. The server cannot obtain the Content-Type that should be multipart/form-data and boundary attribute, which does not fit the expected behavior.

Code

import { fetch } from '@tauri-apps/plugin-http';

const data = new FormData();
data.append("user", username);
data.append("pass", password);

const req = new Request('https://example.com', {
	method: 'POST',
	body: data
});

fetch(req).then(response => console.log(response.text()))

Typical request

POST / HTTP/1.0
Host: 127.0.0.1:8080
Accept: */*
Accept-Encoding: gzip, br
Connection: close
Content-Length: 290
// ↓↓↓ Missing Content-Type will lead to a parser failure. ↓↓↓
Content-Type: multipart/form-data; boundary=------WebKitFormBoundaryL2wbFI7q4LZQ3Cgv
User-Agent: tauri

------WebKitFormBoundaryL2wbFI7q4LZQ3Cgv
Content-Disposition: form-data; name="user"
test@example.com
------WebKitFormBoundaryL2wbFI7q4LZQ3Cgv
Content-Disposition: form-data; name="pass"
thisispassword
------WebKitFormBoundaryL2wbFI7q4LZQ3Cgv--

Tauri info output

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 125.0.2535.51
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-gnu (default)
    - node: 21.7.1
    - npm: 10.5.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.19
    - tauri-build [RUST]: 2.0.0-beta.15
    - wry [RUST]: 0.39.5
    - tao [RUST]: 0.28.0
    - @tauri-apps/api [NPM]: 2.0.0-beta.11
    - @tauri-apps/cli [NPM]: 2.0.0-beta.17

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions