@miniflare/http-server
Advanced tools
Comparing version 2.0.0-rc.2 to 2.0.0-rc.3
@@ -12,11 +12,11 @@ /// <reference types="node" /> | ||
import { PluginContext } from '@miniflare/shared'; | ||
import { Request as Request_2 } from '@miniflare/core'; | ||
import { RequestInfo as RequestInfo_2 } from 'undici'; | ||
import { Response as Response_2 } from '@miniflare/core'; | ||
import { Request } from '@miniflare/core'; | ||
import { RequestInfo } from 'undici'; | ||
import { Response } from '@miniflare/core'; | ||
import { SetupResult } from '@miniflare/shared'; | ||
import { URL as URL_2 } from 'url'; | ||
import { URL } from 'url'; | ||
export declare function convertNodeRequest(req: http.IncomingMessage, upstream?: string, meta?: RequestMeta): Promise<{ | ||
request: Request_2; | ||
url: URL_2; | ||
export declare function convertNodeRequest(req: http.IncomingMessage, meta?: RequestMeta): Promise<{ | ||
request: Request; | ||
url: URL; | ||
}>; | ||
@@ -84,3 +84,3 @@ | ||
cfFetch?: boolean; | ||
cfFetchEndpoint?: RequestInfo_2; | ||
cfFetchEndpoint?: RequestInfo; | ||
clock?: Clock; | ||
@@ -101,3 +101,3 @@ } | ||
export declare type RequestListener = (req: http.IncomingMessage, res?: http.ServerResponse) => Promise<Response_2 | undefined>; | ||
export declare type RequestListener = (req: http.IncomingMessage, res?: http.ServerResponse) => Promise<Response | undefined>; | ||
@@ -104,0 +104,0 @@ export declare interface RequestMeta { |
@@ -17,5 +17,3 @@ var __defProp = Object.defineProperty; | ||
import https from "https"; | ||
import { PassThrough } from "stream"; | ||
import { arrayBuffer } from "stream/consumers"; | ||
import { pipeline } from "stream/promises"; | ||
import { ReadableStream } from "stream/web"; | ||
import { URL } from "url"; | ||
@@ -364,11 +362,27 @@ import zlib from "zlib"; | ||
var liveReloadScriptLength = Buffer.byteLength(liveReloadScript); | ||
async function convertNodeRequest(req, upstream, meta) { | ||
const url = new URL(req.url ?? "", upstream ?? `http://${req.headers.host}`); | ||
async function convertNodeRequest(req, meta) { | ||
const protocol = req.socket.encrypted ? "https" : "http"; | ||
const origin = `${protocol}://${req.headers.host ?? "localhost"}`; | ||
const url = new URL(req.url ?? "", origin); | ||
let body = null; | ||
if (req.method !== "GET" && req.method !== "HEAD") { | ||
if (req.headers["transfer-encoding"]?.includes("chunked")) { | ||
body = req; | ||
} else if (req.headers["content-length"] !== "0") { | ||
body = await arrayBuffer(req); | ||
} | ||
let iterator; | ||
body = new ReadableStream({ | ||
type: "bytes", | ||
start() { | ||
iterator = req[Symbol.asyncIterator](); | ||
}, | ||
async pull(controller) { | ||
const { done, value } = await iterator.next(); | ||
if (done) { | ||
queueMicrotask(() => controller.close()); | ||
} else { | ||
const buffer = Buffer.isBuffer(value) ? value : Buffer.from(value); | ||
controller.enqueue(new Uint8Array(buffer)); | ||
} | ||
}, | ||
async cancel() { | ||
await iterator.return?.(); | ||
} | ||
}); | ||
} | ||
@@ -410,5 +424,5 @@ const proto = meta?.forwardedProto ?? "https"; | ||
return async (req, res) => { | ||
const { CorePlugin, HTTPPlugin: HTTPPlugin2 } = await mf.getPlugins(); | ||
const { HTTPPlugin: HTTPPlugin2 } = await mf.getPlugins(); | ||
const start = process.hrtime(); | ||
const { request, url } = await convertNodeRequest(req, CorePlugin.upstream, await HTTPPlugin2.getRequestMeta(req)); | ||
const { request, url } = await convertNodeRequest(req, await HTTPPlugin2.getRequestMeta(req)); | ||
let response; | ||
@@ -473,15 +487,17 @@ let waitUntil; | ||
if (res) { | ||
const passThrough = new PassThrough(); | ||
const pipelinePromise = pipeline(passThrough, ...encoders, res); | ||
let initialStream = res; | ||
for (let i = encoders.length - 1; i >= 0; i--) { | ||
encoders[i].pipe(initialStream); | ||
initialStream = encoders[i]; | ||
} | ||
if (response.body) { | ||
for await (const chunk of response.body) { | ||
if (chunk) | ||
passThrough.write(chunk); | ||
initialStream.write(chunk); | ||
} | ||
if (liveReloadEnabled) { | ||
passThrough.write(liveReloadScript); | ||
initialStream.write(liveReloadScript); | ||
} | ||
} | ||
passThrough.end(); | ||
await pipelinePromise; | ||
initialStream.end(); | ||
} | ||
@@ -488,0 +504,0 @@ } catch (e) { |
{ | ||
"name": "@miniflare/http-server", | ||
"version": "2.0.0-rc.2", | ||
"version": "2.0.0-rc.3", | ||
"description": "HTTP server module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -39,8 +39,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@miniflare/core": "2.0.0-rc.2", | ||
"@miniflare/shared": "2.0.0-rc.2", | ||
"@miniflare/web-sockets": "2.0.0-rc.2", | ||
"@miniflare/core": "2.0.0-rc.3", | ||
"@miniflare/shared": "2.0.0-rc.3", | ||
"@miniflare/web-sockets": "2.0.0-rc.3", | ||
"kleur": "^4.1.4", | ||
"selfsigned": "^1.10.11", | ||
"undici": "^4.10.2", | ||
"undici": "^4.11.1", | ||
"ws": "^8.2.2", | ||
@@ -50,5 +50,5 @@ "youch": "^2.2.2" | ||
"devDependencies": { | ||
"@miniflare/shared-test": "2.0.0-rc.2", | ||
"@miniflare/shared-test": "2.0.0-rc.3", | ||
"@types/node-forge": "^0.10.4" | ||
} | ||
} |
@@ -58,4 +58,4 @@ # `@miniflare/http-server` | ||
const server = await createServer(mf); | ||
// ...or get Miniflare to start it for you, logging to port | ||
// ...or get Miniflare to start it for you, logging the port | ||
const server2 = await startServer(mf); | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38577
706
+ Added@miniflare/core@2.0.0-rc.3(transitive)
+ Added@miniflare/shared@2.0.0-rc.3(transitive)
+ Added@miniflare/web-sockets@2.0.0-rc.3(transitive)
- Removed@miniflare/core@2.0.0-rc.2(transitive)
- Removed@miniflare/shared@2.0.0-rc.2(transitive)
- Removed@miniflare/web-sockets@2.0.0-rc.2(transitive)
Updated@miniflare/core@2.0.0-rc.3
Updated@miniflare/shared@2.0.0-rc.3
Updatedundici@^4.11.1