From d6227994b896b3e31592231db955ddef3e8356bc Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 7 Nov 2024 10:18:55 -0800 Subject: [PATCH] fix: ensure headers are set on first commit (#1036) --- runtime/fastly/builtins/body.cpp | 4 ---- runtime/fastly/host-api/host_api.cpp | 12 +++++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/runtime/fastly/builtins/body.cpp b/runtime/fastly/builtins/body.cpp index 41b4eb4746..9a7f7a958f 100644 --- a/runtime/fastly/builtins/body.cpp +++ b/runtime/fastly/builtins/body.cpp @@ -4,10 +4,6 @@ #include #include -// TODO(GB) remove once https://github.com/bytecodealliance/StarlingMonkey/pull/75 lands -// clang-format off -#include "builtin.h" -// clang-format on #include "../../../StarlingMonkey/builtins/web/fetch/fetch-errors.h" #include "../../../StarlingMonkey/builtins/web/streams/native-stream-source.h" #include "../../../StarlingMonkey/builtins/web/url.h" diff --git a/runtime/fastly/host-api/host_api.cpp b/runtime/fastly/host-api/host_api.cpp index a1151a1206..c266032939 100644 --- a/runtime/fastly/host-api/host_api.cpp +++ b/runtime/fastly/host-api/host_api.cpp @@ -574,8 +574,18 @@ Result HttpHeaders::FromEntries(vector write_headers(HttpHeaders *headers, std::vector> &list) { + std::vector seen; + seen.reserve(list.size()); + host_api::Result res; for (const auto &[name, value] : list) { - auto res = headers->append(name, value); + if (std::find(seen.begin(), seen.end(), name) == seen.end()) { + // first time seeing a header -> use set in case of existing values on the handle + res = headers->set(name, value); + seen.push_back(name); + } else { + // seen before -> use append + res = headers->append(name, value); + } if (res.is_err()) { return res; }