Merge pull request #2975 from lightpanda-io/eventsoruce-relative

Fix: Allow EventSource with relative URLs
This commit is contained in:
Karl Seguin
2026-07-16 08:30:34 +08:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

@@ -49,6 +49,23 @@
}
</script>
<script id=relative_url type=module>
{
const state = await testing.async();
const es = new EventSource('/sse/simple');
testing.expectEqual('http://127.0.0.1:9582/sse/simple', es.url);
es.onerror = () => { throw new Error('unexpected error'); };
es.onmessage = (e) => {
es.close();
state.resolve(e.data);
};
await state.done((data) => {
testing.expectEqual('first', data);
});
}
</script>
<script id=streaming type=module>
{
// The server only sends "second" after seeing our /sse/flag request, which

View File

@@ -116,7 +116,7 @@ pub fn init(url: []const u8, opts_: ?Opts, exec: *const Execution) !*EventSource
log.debug(.http, "EventSource connecting", .{ .url = resolved });
}
if (std.ascii.startsWithIgnoreCase(url, "http://") == false and std.ascii.startsWithIgnoreCase(url, "https://") == false) {
if (std.ascii.startsWithIgnoreCase(resolved, "http://") == false and std.ascii.startsWithIgnoreCase(resolved, "https://") == false) {
try self.scheduleTask(failConnection, 0, "EventSource.fail");
return self;
}