Skip to content

Commit

Permalink
White space formatting and fixed type test
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeHagar committed Dec 16, 2024
1 parent b83f18c commit cb2b924
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/adapters/bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineWebSocketAdapter<BunAdapter, BunOptions>(
...adapterUtils(peers),
async handleUpgrade(request, server) {
let upgradeHeaders: Headers | undefined;

try {
const result = await hooks.callHook("upgrade", request);
if (result instanceof Response) {
Expand All @@ -53,7 +53,7 @@ export default defineWebSocketAdapter<BunAdapter, BunOptions>(
} satisfies ContextData,
headers: upgradeHeaders,
});

if (!upgradeOK) {
return new Response("Upgrade failed", { status: 500 });
}
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/cloudflare-durable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineWebSocketAdapter<
},
handleDurableUpgrade: async (obj, request) => {
let upgradeHeaders: Headers | undefined;

try {
const result = await hooks.callHook("upgrade", request as Request);
if (result instanceof Response) {
Expand All @@ -57,7 +57,7 @@ export default defineWebSocketAdapter<
peers.add(peer);
(obj as DurableObjectPub).ctx.acceptWebSocket(server);
await hooks.callHook("open", peer);

// eslint-disable-next-line unicorn/no-null
return new Response(null, {
status: 101,
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default defineWebSocketAdapter<CloudflareAdapter, CloudflareOptions>(
...adapterUtils(peers),
handleUpgrade: async (request, env, context) => {
let upgradeHeaders: Headers | undefined;

try {
const result = await hooks.callHook(
"upgrade",
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AdapterOptions, AdapterInstance } from "../adapter.ts";
import type { WebSocket } from "../../types/web.ts";
import { convertResponseToCloseEvent, toBufferLike } from "../utils.ts";
import { toBufferLike } from "../utils.ts";
import { defineWebSocketAdapter, adapterUtils } from "../adapter.ts";
import { AdapterHookable } from "../hooks.ts";
import { Message } from "../message.ts";
Expand Down Expand Up @@ -88,7 +88,7 @@ export default defineWebSocketAdapter<NodeAdapter, NodeOptions>(
const request = new NodeReqProxy(nodeReq);

let res: Response | undefined;

try {
res = await hooks.callHook("upgrade", request);
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions src/adapters/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default defineWebSocketAdapter<SSEAdapter, SSEOptions>((opts = {}) => {
...adapterUtils(peers),
fetch: async (request: Request) => {
let upgradeHeaders: Headers | undefined;

try {
const result = await hooks.callHook("upgrade", request);
if (result instanceof Response) {
Expand Down Expand Up @@ -83,11 +83,11 @@ export default defineWebSocketAdapter<SSEAdapter, SSEOptions>((opts = {}) => {
"Cache-Control": "no-cache",
Connection: "keep-alive",
};

if (opts.bidir) {
headers["x-crossws-id"] = peer.id;
}

if (upgradeHeaders) {
headers = new Headers(headers);
for (const [key, value] of upgradeHeaders) {
Expand Down
7 changes: 2 additions & 5 deletions src/adapters/uws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ export default defineWebSocketAdapter<UWSAdapter, UWSOptions>(
});

let upgradeHeaders: Headers | undefined;

try {
const result = await hooks.callHook(
"upgrade",
new UWSReqProxy(req),
);
const result = await hooks.callHook("upgrade", new UWSReqProxy(req));
if (result instanceof Response) {
// Normal response = headers for upgrade
upgradeHeaders = result.headers;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type HookFn<ArgsT extends any[] = any, RT = void> = (
export interface Hooks {
/** Upgrading */
/**
*
*
* @param request
* @throws {Response}
*/
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export function createDemo<T extends Adapter<any, any>>(
headers: { "x-error": "unauthorized" },
});
}
return {
return new Response(undefined, {
headers: {
"x-powered-by": "cross-ws",
"set-cookie": "cross-ws=1; SameSite=None; Secure",
},
};
});
},
});

Expand Down

0 comments on commit cb2b924

Please sign in to comment.