Truly independent web browser
LibWeb: Use the final URL's origin for EventSource messages
Shannon Booth1ba093ff0ded
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/event_source.rs b/Libraries/LibWeb/Bindings/Rust/src/html/event_source.rsindex 6e58f3ca1f6..dd15cdc1d41 100644--- a/Libraries/LibWeb/Bindings/Rust/src/html/event_source.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/html/event_source.rs@@ -14,8 +14,9 @@ use std::time::{Duration, Instant};use ak::Utf16String;use libjs_rust::api::{EmbedderCell, Gc, GcRefCell, GcWeak, MarkedVec, PrimitiveString, Realm, Trace, Value, Vm};+use liburl_rust::origin::Origin;use liburl_rust::url::ExcludeFragment;-use liburl_rust::{RustUrl, Url};+use liburl_rust::{BasicParseOptions, RustUrl, Url, basic_parse};use crate::bindings::conversions::UsvString;use crate::bindings::environment_settings_object::relevant_settings_object;@@ -23,6 +24,7 @@ use crate::bindings::event_target::{CppEvent, CppEventTarget, GetTheParent};use crate::bindings::interface::{Ref, Wrappable, Wrapped, allocate, cell_into_abi};use crate::bindings::promise::{TaskSource, queue_a_task};use crate::bindings::{CallContext, Exception, WebIdlResult};+use crate::domurl::url_input;use crate::fetch::infrastructure::fetch_controller::CppFetchController;use crate::fetch::infrastructure::http::requests::CppRequest;use crate::fetch::infrastructure::http::response_view::CppResponseView;@@ -66,6 +68,10 @@ pub(crate) struct EventSource {#[gc(untraced)]url: OnceCell<Url>,+ /// The origin of the event stream's final URL.+ #[gc(untraced)]+ final_url_origin: RefCell<Option<Origin>>,+// https://html.spec.whatwg.org/multipage/server-sent-events.html#concept-event-stream-request#[gc(untraced)]request: OnceCell<CppRequest>,@@ -193,6 +199,7 @@ impl EventSource {event_target: CppEventTarget::new(),realm,url: OnceCell::new(),+ final_url_origin: RefCell::new(None),request: OnceCell::new(),reconnection_time: Cell::new(Duration::from_secs(3)),last_event_id: RefCell::new(String::new()),@@ -315,6 +322,13 @@ impl EventSource {else {Self::announce_the_connection(this, vm);+ let final_url = response+ .url(false)+ .expect("A response that is not a network error has a URL");+ let final_url = basic_parse(url_input(final_url.as_units()), BasicParseOptions::new())+ .expect("The URL of a response parses");+ this.final_url_origin.replace(Some(final_url.origin()));+this.pending_data.borrow_mut().clear();this.is_start_of_stream.set(true);this.last_was_cr.set(false);@@ -637,13 +651,16 @@ impl EventSource {} else {event_type.as_str()};- let origin = this.url.get().expect("The constructor sets the URL").origin();+ let origin = this.final_url_origin.borrow();+ let origin = origin+ .as_ref()+ .expect("Interpreting the event stream follows its response");let event = CppEvent::create_message_event(this.realm,r#type,Value::from_string(PrimitiveString::create(vm, Utf16String::from_utf8(data_buffer))),&[],- Some(&origin),+ Some(origin),&last_event_id,None,);diff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.txtindex 6d6c43b0663..611672ac874 100644--- a/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.txt@@ -2,5 +2,5 @@ Harness status: OKFound 1 tests-1 Fail-Fail MessageEvent.origin is the origin of the final URL after a cross-origin redirect\ No newline at end of file+1 Pass+Pass MessageEvent.origin is the origin of the final URL after a cross-origin redirect\ No newline at end of file