Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] plugin-http is unable to perform streaming HTTP requests #2129

Open
Blushyes opened this issue Dec 3, 2024 · 0 comments · May be fixed by #2140
Open

[bug] plugin-http is unable to perform streaming HTTP requests #2129

Blushyes opened this issue Dec 3, 2024 · 0 comments · May be fixed by #2140
Labels
plugin: http question Further information is requested

Comments

@Blushyes
Copy link

Blushyes commented Dec 3, 2024

Describe the bug

Here is demo:

const response = await fetch(`http://xxx:port/xxx`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'text/event-stream',
  },
  body: {/* Some body */},
});

if (!response.body) {
  throw new Error('No response body');
}

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const {done, value} = await reader.read();

  if (done) break;

  const chunk = decoder.decode(value);
  const lines = chunk.split('\n');

  for (const line of lines) {
    if (line.startsWith('data: ')) {
      const data = line.slice(6).trim();

      if (data === '[DONE]') {
        console.log('Stream completed');
        break;
      } else if (data) {
        console.log('Received chunk:', data);
      }
    }
  }
}

With the same code, when I use the browser's native fetch, it runs normally and outputs results in a streaming manner. However, when using Tauri's plugin-http, it blocks until the server outputs all content and then outputs everything at once, which means it blocks at const = await fetch()

Reproduction

No response

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Mac OS 15.1.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.82.0 (f6e511eec 2024-10-15)
    ✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.8.0
    - pnpm: 9.14.2
    - yarn: 1.22.21
    - npm: 10.9.0

[-] Packages
    - tauri 🦀: 2.0.3
    - tauri-build 🦀: 2.0.1
    - wry 🦀: 0.46.0
    - tao 🦀: 0.30.3
    - @tauri-apps/api : 2.0.2 (outdated, latest: 2.1.1)
    - @tauri-apps/cli : 2.0.0-rc.13 (outdated, latest: 2.1.0)

[-] Plugins
    - tauri-plugin-dialog 🦀: 2.0.1
    - @tauri-apps/plugin-dialog : 2.0.1
    - tauri-plugin-fs 🦀: 2.0.1
    - @tauri-apps/plugin-fs : 2.0.2
    - tauri-plugin-http 🦀: 2.0.1
    - @tauri-apps/plugin-http : 2.0.1
    - tauri-plugin-sql 🦀: 2.0.1
    - @tauri-apps/plugin-sql : 2.0.1
    - tauri-plugin-single-instance 🦀: 2.0.1
    - @tauri-apps/plugin-single-instance : not installed!
    - tauri-plugin-log 🦀: 2.0.1
    - @tauri-apps/plugin-log : 2.0.0
    - tauri-plugin-os 🦀: 2.0.1
    - @tauri-apps/plugin-os : 2.0.0
    - tauri-plugin-updater 🦀: 2.0.2
    - @tauri-apps/plugin-updater : 2.0.0
    - tauri-plugin-notification 🦀: 2.0.1
    - @tauri-apps/plugin-notification : 2.0.0
    - tauri-plugin-autostart 🦀: 2.0.1
    - @tauri-apps/plugin-autostart : 2.0.0
    - tauri-plugin-process 🦀: 2.0.1
    - @tauri-apps/plugin-process : 2.0.0
    - tauri-plugin-shell 🦀: 2.0.1
    - @tauri-apps/plugin-shell : 2.0.1
    - tauri-plugin-global-shortcut 🦀: 2.0.1
    - @tauri-apps/plugin-global-shortcut : 2.0.0

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

Stack trace

No response

Additional context

No response

@FabianLars FabianLars transferred this issue from tauri-apps/tauri Dec 3, 2024
@FabianLars FabianLars added question Further information is requested plugin: http labels Dec 3, 2024
@robertlong robertlong linked a pull request Dec 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: http question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants