From ef1adf8080ee6d320dd3da6f54c0f31dd8e9b539 Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Tue, 27 Oct 2026 20:07:12 +0700 Subject: [PATCH] net/http: fix the amalgamation for csrf and the file transport burrow-gen puts a source file in the package of the first burrow header it includes. http_csrf.c and http_filetransport.c started with core.h and chan.h, which have no burrow:package line, so the amalgamation and the docs examples job failed. Include net/http.h first, and drop http_csrf.c's own S macro, which clashes with core.h's. --- src/net/http_csrf.c | 18 +++++++++--------- src/net/http_filetransport.c | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/net/http_csrf.c b/src/net/http_csrf.c index 494cf1a1..ceda681a 100644 --- a/src/net/http_csrf.c +++ b/src/net/http_csrf.c @@ -6,13 +6,14 @@ * Use of this source code is governed by a BSD-style licence that can be found * in the LICENSE file. */ +#include "burrow/net/http.h" + #include "burrow/core.h" #include "burrow/error.h" #include "burrow/fmt.h" #include "burrow/map.h" #include "burrow/mem.h" #include "burrow/mem/arena.h" -#include "burrow/net/http.h" #include "burrow/net/url.h" #include "burrow/sync.h" #include "burrow/type.h" @@ -21,8 +22,6 @@ #include #include -#define S(lit) BURROW_S(lit) - HttpCrossOriginProtection *http_new_cross_origin_protection(Alloc *a) { HttpCrossOriginProtection *c = (HttpCrossOriginProtection *)mem_alloc( a, sizeof(HttpCrossOriginProtection), _Alignof(HttpCrossOriginProtection)); @@ -154,17 +153,18 @@ static bool coh_is_request_exempt(HttpCrossOriginProtection *c, const HttpReques Error http_cross_origin_protection_check(HttpCrossOriginProtection *c, const HttpRequest *req) { - if (str_eq(req->method, S("GET")) || str_eq(req->method, S("HEAD")) || - str_eq(req->method, S("OPTIONS"))) { + if (str_eq(req->method, BURROW_S("GET")) || str_eq(req->method, BURROW_S("HEAD")) || + str_eq(req->method, BURROW_S("OPTIONS"))) { /* Safe methods are always allowed. */ return BURROW_NO_ERROR; } - Str site = http_header_get(req->header, S("Sec-Fetch-Site")); + Str site = http_header_get(req->header, BURROW_S("Sec-Fetch-Site")); if (site.len == 0) { /* No Sec-Fetch-Site header is present. * Fallthrough to check the Origin header. */ - } else if (str_eq(site, S("same-origin")) || str_eq(site, S("none"))) { + } else if (str_eq(site, BURROW_S("same-origin")) || + str_eq(site, BURROW_S("none"))) { return BURROW_NO_ERROR; } else { if (coh_is_request_exempt(c, req)) @@ -172,7 +172,7 @@ Error http_cross_origin_protection_check(HttpCrossOriginProtection *c, return coh_err_cross_origin_request; } - Str origin = http_header_get(req->header, S("Origin")); + Str origin = http_header_get(req->header, BURROW_S("Origin")); if (origin.len == 0) { /* Neither Sec-Fetch-Site nor Origin headers are present. * Either the request is same-origin or not a browser request. */ @@ -221,7 +221,7 @@ static bool coh_is_request_exempt(HttpCrossOriginProtection *c, } sync_rw_mutex_r_lock(&c->mu); - Str origin = http_header_get(req->header, S("Origin")); + Str origin = http_header_get(req->header, BURROW_S("Origin")); /* The request matches a trusted origin. */ bool *trusted = NULL; if (origin.len != 0 && c->trusted != NULL) diff --git a/src/net/http_filetransport.c b/src/net/http_filetransport.c index f00cd137..584995b1 100644 --- a/src/net/http_filetransport.c +++ b/src/net/http_filetransport.c @@ -6,6 +6,8 @@ * Use of this source code is governed by a BSD-style licence that can be found * in the LICENSE file. */ +#include "burrow/net/http.h" + #include "burrow/chan.h" #include "burrow/core.h" #include "burrow/error.h" @@ -15,7 +17,6 @@ #include "burrow/mem.h" #include "burrow/mem/arena.h" #include "burrow/mem/heap.h" -#include "burrow/net/http.h" #include "burrow/proc.h" #include "burrow/type.h"