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

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

Closed
1 of 3 tasks
myhrmans opened this issue Oct 7, 2022 · 7 comments
Closed
1 of 3 tasks

Comments

@myhrmans
Copy link

myhrmans commented Oct 7, 2022

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?

  • Yes
  • No
  • I have tried for a few days but can't solve it since my knowledge is not enough

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

@FabianLars FabianLars transferred this issue from tauri-apps/tao Oct 7, 2022
@myhrmans
Copy link
Author

myhrmans commented Oct 7, 2022

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

@myhrmans
Copy link
Author

myhrmans commented Oct 8, 2022

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

@myhrmans myhrmans changed the title Can't make XHR request Can't make XHR request because wry is sending Content-Lenght header in GET request Oct 10, 2022
@myhrmans
Copy link
Author

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
Copy link
Member

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_delete_event(|_, _| {
    gtk::main_quit();
    Inhibit(false)
  });

  gtk::main();
}
  1. When the webview opens, click Log In with SAML SSO button
  2. enter martin.myhrman@volvocars.com in the email field
  3. 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
Copy link
Member

wusyong commented Oct 12, 2022

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

@myhrmans
Copy link
Author

myhrmans commented Nov 22, 2022

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
Copy link
Member

wusyong commented Jan 30, 2023

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

@wusyong wusyong closed this as completed Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants