Skip to content

Commit

Permalink
fix: trailers unsupported errors (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Dec 15, 2023
1 parent fff3c57 commit 056e065
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions packages/preview2-shim/lib/nodejs/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IncomingBody {
if (incomingBody.#finished)
throw new Error("incoming body already finished");
incomingBody.#finished = true;
return futureTrailersCreate(new Fields([]), false);
return futureTrailersCreate();
}
[symbolDispose]() {
if (!this.#finished) {
Expand Down Expand Up @@ -99,18 +99,24 @@ delete IncomingRequest._create;

class FutureTrailers {
_id = futureCnt++;
#value;
#isError;
#requested = false;
subscribe() {
// TODO
return pollableCreate(0);
}
get() {
return { tag: this.#isError ? "err" : "ok", val: this.#value };
if (this.#requested)
return { tag: "err" };
this.#requested = true;
return {
tag: "ok",
val: {
tag: "ok",
val: undefined,
}
};
}
static _create(value, isError) {
static _create() {
const res = new FutureTrailers();
res.#value = value;
res.#isError = isError;
return res;
}
}
Expand Down Expand Up @@ -328,7 +334,7 @@ class OutgoingBody {
* @param {Fields | undefined} trailers
*/
static finish(body, trailers) {
if (trailers) throw new Error("Internal error: Trailers TODO");
if (trailers) throw { tag: "internal-error", val: "trailers unsupported" };
// this will verify content length, and also verify not already finished
// throwing errors as appropriate
if (body.#outputStreamId)
Expand Down Expand Up @@ -419,7 +425,17 @@ class FutureIncomingResponse {
[symbolDispose]() {
if (this.#pollId) ioCall(FUTURE_DISPOSE | HTTP, this.#pollId);
}
static _create(method, scheme, authority, pathWithQuery, headers, body, connectTimeout, betweenBytesTimeout, firstByteTimeout) {
static _create(
method,
scheme,
authority,
pathWithQuery,
headers,
body,
connectTimeout,
betweenBytesTimeout,
firstByteTimeout
) {
const res = new FutureIncomingResponse();
res.#pollId = ioCall(HTTP_CREATE_REQUEST, null, {
method,
Expand All @@ -430,7 +446,7 @@ class FutureIncomingResponse {
body,
connectTimeout,
betweenBytesTimeout,
firstByteTimeout
firstByteTimeout,
});
return res;
}
Expand Down

0 comments on commit 056e065

Please sign in to comment.