-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
467 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type ConnInfo = Readonly<{ | ||
/** The local address of the connection. */ | ||
readonly localAddr: Deno.Addr; | ||
/** The remote address of the connection. */ | ||
readonly remoteAddr: Deno.Addr; | ||
alpnProtocol: string; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ConnInfo } from "./ConnInfo.ts"; | ||
|
||
// } | ||
|
||
export type Handler = ( | ||
request: Request, | ||
connInfo: ConnInfo, | ||
) => Response | Promise<Response>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Handler } from "./Handler.ts"; | ||
|
||
export type Handlers = Partial<{ | ||
request: Handler; | ||
connect: Handler; | ||
upgrade: Handler; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ConnInfo } from "./ConnInfo.ts"; | ||
import { Handler } from "./Handler.ts"; | ||
|
||
export type ServeHttpInit = Partial< | ||
Deno.ListenOptions & { | ||
onNotFound?: Handler; | ||
signal?: AbortSignal; | ||
port?: number; | ||
hostname?: string; | ||
|
||
onError?: ( | ||
// deno-lint-ignore no-explicit-any | ||
reason: any, | ||
request: Request, | ||
connInfo: ConnInfo, | ||
) => Response | PromiseLike<Response>; | ||
onListen?: (params: { hostname: string; port: number }) => void; | ||
} | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ConnInfo } from "./ConnInfo.ts"; | ||
import { Handler } from "./Handler.ts"; | ||
|
||
// function upgrade(req: Request, connInfo: ConnInfo) { | ||
// const { socket, response } = Deno.upgradeWebSocket(req); | ||
// const { url, headers, method } = req; | ||
// const data = { | ||
// ...connInfo, | ||
// url, | ||
// method, | ||
// headers: Object.fromEntries(headers), | ||
// }; | ||
// const body = JSON.stringify(data); | ||
// console.log("upgrade", body); | ||
// socket.addEventListener("open", () => { | ||
// socket.send(body); | ||
// socket.close(); | ||
// }); | ||
// return response; | ||
// } | ||
// async function main() { | ||
// let { port, hostname, certFile, keyFile } = parse(Deno.args); | ||
// if (port || hostname || certFile || keyFile) { | ||
// port ??= 8000; | ||
// hostname ??= "0.0.0.0"; | ||
// await serve_https( | ||
// { request: handler, upgrade }, | ||
// { port, hostname, certFile, keyFile } | ||
// ); | ||
// } else { | ||
// console.log("Listening on http://localhost:8000"); | ||
// await serve(handler, { hostname: "0.0.0.0", port: 8000 }); | ||
// } | ||
// } | ||
|
||
export type ServeHttpsInit = Partial< | ||
Deno.ListenTlsOptions & { | ||
onNotFound?: Handler; | ||
signal?: AbortSignal; | ||
port?: number; | ||
hostname?: string; | ||
certFile?: string; | ||
keyFile?: string; | ||
|
||
onError?: ( | ||
// deno-lint-ignore no-explicit-any | ||
reason: any, | ||
request: Request, | ||
connInfo: ConnInfo, | ||
) => Response | PromiseLike<Response>; | ||
onListen?: (params: { hostname: string; port: number }) => void; | ||
} | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function hostnameForDisplay(hostname: string) { | ||
// If the hostname is "0.0.0.0", we display "localhost" in console | ||
// because browsers in Windows don't resolve "0.0.0.0". | ||
// See the discussion in https://github.com/denoland/deno_std/issues/1165 | ||
return hostname === "0.0.0.0" ? "localhost" : hostname; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function is_connect_or_upgrade(request: Request) { | ||
return ( | ||
request.method === "CONNECT" || | ||
request.headers.get("Connection")?.toLowerCase() === "upgrade" | ||
); | ||
} |
Oops, something went wrong.