tauri-apps / wry

Cross-platform WebView library in Rust for Tauri.
Apache License 2.0
3.58k stars 268 forks source link

Can't make XHR request because wry is sending Content-Lenght header in GET request #717

Closed myhrmans closed 1 year ago

myhrmans commented 2 years ago

Describe the bug Have an issue in the wry window where I can't seem to make a XHR request when trying to sign in to a service.

Error: XHR for "/api/saml" failed with status 400

Failed to load resource: the server responded with a status of 400 (Bad Request)

The specific service Im trying to sign into is https://figma.com/mirror using SAML SSO.

Steps To Reproduce On Linux clone this repository https://github.com/myhrmans/tauri-wry-bug-xhr-error Then follow the instructions in the repo.

Platform and Versions (please complete the following information): OS: Ubuntu 22.04.1 LTS Rustc: rustc 1.64.0 (a55dd71d5 2022-09-19)

Would you assign yourself to resolve this bug?

Additional context This issue is only present on systems using the webkitgtk as far as I have tested. webview2 does not have this issue.

myhrmans commented 2 years ago

Please see example repo and how to reproduce the error: https://github.com/myhrmans/tauri-wry-bug-xhr-error

myhrmans commented 1 year ago

Can confirm. Can't replicate the issue in windows. Seems to be working as intended.

myhrmans commented 1 year ago

After some more digging I found out that the request sent by wry has a header that is Content-Length: 0

Looking here: https://www.rfc-editor.org/rfc/rfc7230

A user agent SHOULD NOT send a Content-Length header field when the request message does not contain a payload body and the method semantics do not anticipate such a body.

Copying the request over into Postman and removing the Content-Length: 0 makes the request return a 200.

amrbashir commented 1 year ago

I had a conversation with @myhrmans in discord and reached to the conclusion that this seems to be a bug in webkit2gtk.

In order to reproduce this issue, we use webkit2gtk-rs basic example:

  1. clone webkit2gtk-rs repo:
    git clone https://github.com/tauri-apps/webkit2gtk-rs
  2. change examples/main.rs to this (simply point the webview to https://figma.com/mirror):
    
    extern crate gio;
    extern crate glib;
    extern crate gtk;
    extern crate webkit2gtk;

[cfg(feature = "v2_4")]

use glib::ToVariant; use gtk::{prelude::*, Inhibit, Window, WindowType};

[cfg(feature = "v2_6")]

use webkit2gtk::UserContentManager; use webkit2gtk::{ traits::{SettingsExt, WebContextExt, WebViewExt}, WebContext, WebView, };

fn main() { gtk::init().unwrap();

let window = Window::new(WindowType::Toplevel); let context = WebContext::default().unwrap();

[cfg(feature = "v2_4")]

context.set_web_extensions_initialization_user_data(&"webkit".to_variant()); context.set_web_extensions_directory("../webkit2gtk-webextension-rs/example/target/debug/");

[cfg(feature = "v2_6")]

let webview = WebView::new_with_context_and_user_content_manager(&context, &UserContentManager::new());

[cfg(not(feature = "v2_6"))]

let webview = WebView::with_context(&context); webview.load_uri("https://figma.com/mirror"); window.add(&webview);

let settings = WebViewExt::settings(&webview).unwrap(); settings.set_enable_developer_extras(true);

/let inspector = webview.get_inspector().unwrap(); inspector.show();/

window.show_all();

webview.run_javascript("alert('Hello');", None::<&gio::Cancellable>, |_result| {});

[cfg(feature = "v2_22")]

webview.run_javascript("42", None::<&gio::Cancellable>, |result| match result { Ok(result) => { let value = result.js_value(); println!("is_boolean: {}", value.is_boolean(&context)); println!("is_number: {}", value.is_number(&context)); println!("{:?}", value.to_number(&context)); println!("{:?}", value.to_boolean(&context)); } Err(error) => println!("{}", error), });

let cancellable = gio::Cancellable::new(); webview.run_javascript("42", Some(&cancellable), |result| match result { Ok(result) => { let context = result.global_context().unwrap(); let value = result.value().unwrap(); println!("is_boolean: {}", value.is_boolean(&context)); println!("is_number: {}", value.is_number(&context)); println!("{:?}", value.to_number(&context)); println!("{:?}", value.to_boolean(&context)); } Err(error) => println!("{}", error), });

window.connect_deleteevent(|, _| { gtk::main_quit(); Inhibit(false) });

gtk::main(); }


3. When the webview opens, click `Log In with SAML SSO` button
4. enter `martin.myhrman@volvocars.com` in the email field
5. check console for the error

The annoying thing is that same reproduction works fine in Gnome Web (previously called Epiphany) which depends on webkit2gtk. cc @wusyong 
wusyong commented 1 year ago

I tested with plan C and can confirm the same error :/ https://github.com/wusyong/gtkbrowser

myhrmans commented 1 year ago

Bugreport in webkit: https://bugs.webkit.org/show_bug.cgi?id=247970#c2

Seems to be a problem in soup2, a fix is already present in soup3. So upgrading to soup3 would solve this issue.

wusyong commented 1 year ago

wry v0.25 now uses soup3 and tauri next branch has also merged it.