Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add an ability to inject an arbitrary set of headers to KV re… #145

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/workerd/api/kv.c++
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ jsg::Promise<KvNamespace::GetWithMetadataResult> KvNamespace::getWithMetadata(
auto urlStr = url.toString(kj::Url::Context::HTTP_PROXY_REQUEST);
auto headers = kj::HttpHeaders(context.getHeaderTable());
headers.add(FLPROD_405_HEADER, kj::str(urlStr));
for (const auto& header: additionalHeaders) {
headers.add(header.name.asPtr(), header.value.asPtr());
}

return context.awaitIo(js,
client->request(kj::HttpMethod::GET, urlStr, headers).response,
Expand Down Expand Up @@ -214,9 +211,6 @@ jsg::Promise<jsg::Value> KvNamespace::list(
auto urlStr = url.toString(kj::Url::Context::HTTP_PROXY_REQUEST);
auto headers = kj::HttpHeaders(context.getHeaderTable());
headers.add(FLPROD_405_HEADER, kj::str(urlStr));
for (const auto& header: additionalHeaders) {
headers.add(header.name.asPtr(), header.value.asPtr());
}

return context.awaitIo(js,
client->request(kj::HttpMethod::GET, urlStr, headers).response,
Expand Down Expand Up @@ -317,9 +311,6 @@ jsg::Promise<void> KvNamespace::put(

auto urlStr = url.toString(kj::Url::Context::HTTP_PROXY_REQUEST);
headers.add(FLPROD_405_HEADER, kj::str(urlStr));
for (const auto& header: additionalHeaders) {
headers.add(header.name.asPtr(), header.value.asPtr());
}

auto promise = context.waitForOutputLocks()
.then([&context, client = kj::mv(client), urlStr = kj::mv(urlStr), headers = kj::mv(headers),
Expand Down Expand Up @@ -376,13 +367,9 @@ jsg::Promise<void> KvNamespace::delete_(jsg::Lock& js, kj::String name) {
auto client = context.getHttpClient(subrequestChannel, true, nullptr, "kv_delete"_kj);
auto urlStr = kj::str("https://fake-host/", kj::encodeUriComponent(name), "?urlencoded=true");
auto promise = context.waitForOutputLocks()
.then([this, &context, client = kj::mv(client), urlStr = kj::mv(urlStr)]() mutable {
.then([&context, client = kj::mv(client), urlStr = kj::mv(urlStr)]() mutable {
auto headers = kj::HttpHeaders(context.getHeaderTable());
headers.add(FLPROD_405_HEADER, kj::str(urlStr));
for (const auto& header: additionalHeaders) {
headers.add(header.name.asPtr(), header.value.asPtr());
}

return client->request(kj::HttpMethod::DELETE, urlStr, headers,
uint64_t(0))
.response.then([](kj::HttpClient::Response&& response) mutable {
Expand Down
10 changes: 1 addition & 9 deletions src/workerd/api/kv.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ class KvNamespace: public jsg::Object {
// A capability to a KV namespace.

public:
struct AdditionalHeader {
kj::String name;
kj::String value;
};

explicit KvNamespace(kj::Array<AdditionalHeader> additionalHeaders, uint subrequestChannel)
: additionalHeaders(kj::mv(additionalHeaders)), subrequestChannel(subrequestChannel) {}
explicit KvNamespace(uint subrequestChannel): subrequestChannel(subrequestChannel) {}
// `subrequestChannel` is what to pass to IoContext::getHttpClient() to get an HttpClient
// representing this namespace.
// `additionalHeaders` is what gets appended to every outbound request.

struct GetOptions {
jsg::Optional<kj::String> type;
Expand Down Expand Up @@ -97,7 +90,6 @@ class KvNamespace: public jsg::Object {
}

private:
kj::Array<AdditionalHeader> additionalHeaders;
uint subrequestChannel;
};

Expand Down
3 changes: 1 addition & 2 deletions src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ void WorkerdApiIsolate::compileGlobals(
}

KJ_CASE_ONEOF(ns, Global::KvNamespace) {
value = lock.wrap(context, jsg::alloc<api::KvNamespace>(
kj::Array<api::KvNamespace::AdditionalHeader>{}, ns.subrequestChannel));
value = lock.wrap(context, jsg::alloc<api::KvNamespace>(ns.subrequestChannel));
}

KJ_CASE_ONEOF(r2, Global::R2Bucket) {
Expand Down