Skip to content

Lightpanda: the headless browser designed for AI and automation

add origin conditionally on no_cors

Muki Kiboigo868882b0c8b6
diff --git a/src/network/CorsGate.zig b/src/network/CorsGate.zig
index f268ab91e..50f1139b0 100644
--- a/src/network/CorsGate.zig
+++ b/src/network/CorsGate.zig
@@ -191,10 +191,17 @@ pub fn check(self: *CorsGate, transfer: *Transfer) !Result {
}
const origin = req.origin orelse "null";
- try transfer.setHeader(ORIGIN, origin, .{});
transfer._cors_cross_origin = true;
+ // https://fetch.spec.whatwg.org/#append-a-request-origin-header
+ //
+ // If the request is no cors, we only add the origin if it is not HEAD or GET.
+ // TODO: Should use referrer policy.
+ if (req.request_mode != .no_cors or (req.method != .HEAD and req.method != .GET)) {
+ try transfer.setHeader("Origin", origin, .{});
+ }
+
if (req.request_mode == .no_cors) {
log.debug(.cors, "cross origin", .{
.url = req.url,