-
Notifications
You must be signed in to change notification settings - Fork 14
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
1 parent
104ec88
commit 5716db0
Showing
3 changed files
with
119 additions
and
71 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
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,23 @@ | ||
import type { IncomingMessage } from "node:http"; | ||
|
||
export const createRequest = (req: IncomingMessage | Request): Request => { | ||
if (req instanceof Request) { | ||
return req.clone(); | ||
} | ||
|
||
const url = `http://${req.headers.host}${req.url}`; | ||
|
||
const controller = new AbortController(); | ||
|
||
req.once("close", () => { | ||
controller.abort(); | ||
}); | ||
|
||
const request = new Request(url, { | ||
method: req.method, | ||
headers: req.headers as Record<string, string>, | ||
signal: controller.signal, | ||
}); | ||
|
||
return request; | ||
}; |
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,10 @@ | ||
import type { ServerResponse } from "http"; | ||
import * as stream from "node:stream"; | ||
|
||
export const createResponse = (res: ServerResponse | Response): Response => { | ||
if (res instanceof Response) { | ||
return res.clone(); | ||
} | ||
|
||
const response = stream.Writable.toWeb(res); | ||
}; |