From a3a2fb1e4fa0d67f19e6679aececa6c3ad882abb Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 2 Jan 2022 00:22:52 -0800 Subject: [PATCH] Update http.zig --- src/http.zig | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/http.zig b/src/http.zig index f101b5b383..34b5dea0a2 100644 --- a/src/http.zig +++ b/src/http.zig @@ -127,13 +127,14 @@ pub const RequestContext = struct { } if (protocol == null) { - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto determine_protocol: { + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests if (this.header("Upgrade-Insecure-Requests") != null) { protocol = "https"; break :determine_protocol; } + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto if (this.header("X-Forwarded-Proto")) |proto| { if (strings.eqlComptime(proto, "https")) { protocol = "https"; @@ -159,15 +160,16 @@ pub const RequestContext = struct { } } - if (this.header("Origin")) |origin| { - this.origin = ZigURL.parse(origin); - return; + if (protocol == null) { + if (this.header("Origin")) |origin| { + this.origin = ZigURL.parse(origin); + return; + } } } if (host != null or protocol != null) { // Proxies like Caddy might only send X-Forwarded-Proto if the host matches - // In that case, const display_protocol = protocol orelse @as(string, "http"); var display_host = host orelse (if (protocol != null) this.header("Host") else null) orelse