mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-13 14:20:01 -04:00
fix error while constructing responses
"Response with null body status cannot have body"
This commit is contained in:
parent
d449ed2e42
commit
52a55f616b
2 changed files with 15 additions and 11 deletions
|
@ -9,13 +9,8 @@ import {
|
|||
} from "bare-client-custom";
|
||||
import { Connection } from "./Connection";
|
||||
|
||||
// export class Adrift {
|
||||
// bareclient:AdriftBareClient,
|
||||
// constructor(connection:Connection){
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// https://fetch.spec.whatwg.org/#statuses
|
||||
const NULL_BODY_STATUSES = [101, 103, 204, 205, 304];
|
||||
|
||||
export class AdriftBareClient extends Client {
|
||||
constructor(private connection: Connection) {
|
||||
|
@ -38,7 +33,7 @@ export class AdriftBareClient extends Client {
|
|||
console.log({ body });
|
||||
throw new Error("bare-client-custom passed an unexpected body type");
|
||||
}
|
||||
let { payload, body: respBody } = await this.connection.httprequest({
|
||||
let { payload, body: respRawBody } = await this.connection.httprequest({
|
||||
method,
|
||||
requestHeaders,
|
||||
body,
|
||||
|
@ -51,6 +46,18 @@ export class AdriftBareClient extends Client {
|
|||
}
|
||||
}
|
||||
|
||||
let respBody: ArrayBuffer | null = respRawBody;
|
||||
if (
|
||||
respBody.byteLength == 0 ||
|
||||
NULL_BODY_STATUSES.includes(payload.status)
|
||||
) {
|
||||
respBody = null;
|
||||
}
|
||||
|
||||
console.log("constructing Response", {
|
||||
status: payload.status,
|
||||
body: respBody?.byteLength,
|
||||
});
|
||||
return new Response(respBody, {
|
||||
status: payload.status,
|
||||
statusText: payload.statusText,
|
||||
|
|
|
@ -43,12 +43,9 @@ export class Connection {
|
|||
let requestType = view.getUint8(cursor) as S2CRequestType;
|
||||
cursor += 1;
|
||||
|
||||
console.log(requestID, requestType);
|
||||
|
||||
const msgText = () => new TextDecoder().decode(data.slice(cursor));
|
||||
const msgJSON = () => JSON.parse(msgText());
|
||||
|
||||
console.log({ requestType });
|
||||
switch (requestType) {
|
||||
case S2CRequestTypes.HTTPResponseStart:
|
||||
const payload = msgJSON();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue