Skip to content

Commit 84f783e

Browse files
authored
fix: send content-type header on data path requests (#151)
The KV Connect spec requires clients to send a Content-Type header with the value application/x-protobuf on all data path requests (proto/kv-connect.md line 194). Neither the Rust remote client nor the npm client library did, which breaks servers and proxies that reject protobuf bodies without a content type. * remote/lib.rs: Metadata::headers() gains the content-type entry (the JSON metadata exchange already sent application/json) * npm/src/kv_connect_api.ts: fetchProtobuf sends the same header for all protocol versions Fixes #81.
1 parent b63cfd9 commit 84f783e

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

npm/src/kv_connect_api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ async function fetchProtobuf(
175175
): Promise<Uint8Array | ReadableStream<Uint8Array>> {
176176
const headers = {
177177
authorization: `Bearer ${accessToken}`,
178+
"content-type": "application/x-protobuf",
178179
...(version === 1 ? { "x-transaction-domain-id": databaseId } : {
179180
"x-denokv-version": version.toString(),
180181
"x-denokv-database-id": databaseId,

remote/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ struct Metadata {
102102

103103
impl Metadata {
104104
pub fn headers(&self) -> HeaderMap {
105-
let mut headers = HeaderMap::with_capacity(3);
105+
let mut headers = HeaderMap::with_capacity(4);
106106
headers.insert(
107107
"authorization",
108108
format!("Bearer {}", self.token).try_into().unwrap(),
109109
);
110+
headers.insert(
111+
"content-type",
112+
HeaderValue::from_static("application/x-protobuf"),
113+
);
110114
match self.version {
111115
ProtocolVersion::V1 => {
112116
headers.insert(

0 commit comments

Comments
 (0)