From 922e4128ee29f6489c8f474412b5190c46c9e074 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 6 Nov 2024 15:33:10 -0800 Subject: [PATCH 1/2] fix: ensure headers are set on first commit --- runtime/fastly/builtins/body.cpp | 4 ---- runtime/fastly/host-api/host_api.cpp | 11 ++++++++++- 2 files changed, 10 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..5d7b7d8997 100644 --- a/runtime/fastly/host-api/host_api.cpp +++ b/runtime/fastly/host-api/host_api.cpp @@ -574,8 +574,17 @@ Result HttpHeaders::FromEntries(vector write_headers(HttpHeaders *headers, std::vector> &list) { + std::vector seen(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; } From c5fd636fcf220fedd3b683a67b52c556b524f411 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 6 Nov 2024 16:01:53 -0800 Subject: [PATCH 2/2] fixup --- runtime/fastly/host-api/host_api.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/fastly/host-api/host_api.cpp b/runtime/fastly/host-api/host_api.cpp index 5d7b7d8997..c266032939 100644 --- a/runtime/fastly/host-api/host_api.cpp +++ b/runtime/fastly/host-api/host_api.cpp @@ -574,7 +574,8 @@ Result HttpHeaders::FromEntries(vector write_headers(HttpHeaders *headers, std::vector> &list) { - std::vector seen(list.size()); + std::vector seen; + seen.reserve(list.size()); host_api::Result res; for (const auto &[name, value] : list) { if (std::find(seen.begin(), seen.end(), name) == seen.end()) {