Skip to content

Commit d622799

Browse files
authored
fix: ensure headers are set on first commit (#1036)
1 parent 5c3eba0 commit d622799

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

runtime/fastly/builtins/body.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
#include <optional>
55
#include <string>
66

7-
// TODO(GB) remove once https://github.com/bytecodealliance/StarlingMonkey/pull/75 lands
8-
// clang-format off
9-
#include "builtin.h"
10-
// clang-format on
117
#include "../../../StarlingMonkey/builtins/web/fetch/fetch-errors.h"
128
#include "../../../StarlingMonkey/builtins/web/streams/native-stream-source.h"
139
#include "../../../StarlingMonkey/builtins/web/url.h"

runtime/fastly/host-api/host_api.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,18 @@ Result<HttpHeaders *> HttpHeaders::FromEntries(vector<tuple<HostString, HostStri
574574
Result<Void>
575575
write_headers(HttpHeaders *headers,
576576
std::vector<std::tuple<host_api::HostString, host_api::HostString>> &list) {
577+
std::vector<std::string_view> seen;
578+
seen.reserve(list.size());
579+
host_api::Result<host_api::Void> res;
577580
for (const auto &[name, value] : list) {
578-
auto res = headers->append(name, value);
581+
if (std::find(seen.begin(), seen.end(), name) == seen.end()) {
582+
// first time seeing a header -> use set in case of existing values on the handle
583+
res = headers->set(name, value);
584+
seen.push_back(name);
585+
} else {
586+
// seen before -> use append
587+
res = headers->append(name, value);
588+
}
579589
if (res.is_err()) {
580590
return res;
581591
}

0 commit comments

Comments
 (0)