@web-widget/node 1.72.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/node.js +77 -3
  2. package/package.json +1 -1
package/dist/node.js CHANGED
@@ -19,11 +19,85 @@ if (!Reflect.get(global, "DISABLE_INSTALL_MCA_SHIMS")) {
19
19
  // src/adapter.ts
20
20
  import {
21
21
  buildToFetchEvent,
22
- buildToRequest,
23
22
  mergeIntoServerResponse,
24
23
  toOutgoingHeaders
25
24
  } from "@edge-runtime/node-utils";
26
25
  import primitives2 from "@edge-runtime/primitives";
26
+
27
+ // src/incoming-request.ts
28
+ import {
29
+ buildToHeaders,
30
+ buildToReadableStream
31
+ } from "@edge-runtime/node-utils";
32
+ function isHttp2PseudoHeader(name) {
33
+ return name.startsWith(":");
34
+ }
35
+ function headerValue(value) {
36
+ if (value === void 0) {
37
+ return void 0;
38
+ }
39
+ return Array.isArray(value) ? value[0] : value;
40
+ }
41
+ function sanitizeIncomingHttpHeaders(headers) {
42
+ const sanitized = {};
43
+ for (const [key, value] of Object.entries(headers)) {
44
+ if (!isHttp2PseudoHeader(key)) {
45
+ sanitized[key] = value;
46
+ }
47
+ }
48
+ if (!sanitized.host) {
49
+ const authority = headerValue(headers[":authority"]);
50
+ if (authority) {
51
+ sanitized.host = authority;
52
+ }
53
+ }
54
+ return sanitized;
55
+ }
56
+ function computeRequestOrigin(headers, defaultOrigin) {
57
+ var _a;
58
+ const authority = (_a = headerValue(headers.host)) != null ? _a : headerValue(headers[":authority"]);
59
+ if (!authority) {
60
+ return defaultOrigin;
61
+ }
62
+ let protocol = "http";
63
+ if (defaultOrigin) {
64
+ try {
65
+ protocol = new URL(defaultOrigin).protocol.replace(":", "") || "http";
66
+ } catch {
67
+ }
68
+ }
69
+ const scheme = headerValue(headers[":scheme"]);
70
+ if (scheme === "http" || scheme === "https") {
71
+ protocol = scheme;
72
+ }
73
+ const [, port] = authority.split(":");
74
+ if (port === "443") {
75
+ protocol = "https";
76
+ }
77
+ return `${protocol}://${authority}`;
78
+ }
79
+ function buildToRequestWithHttp2Compat(dependencies2) {
80
+ const toHeaders = buildToHeaders(dependencies2);
81
+ const toReadableStream = buildToReadableStream(dependencies2);
82
+ const { Request: Request2 } = dependencies2;
83
+ return function toRequest(request, options) {
84
+ var _a, _b;
85
+ const base = computeRequestOrigin(request.headers, options.defaultOrigin);
86
+ const headers = sanitizeIncomingHttpHeaders(request.headers);
87
+ return new Request2(
88
+ String(
89
+ ((_a = request.url) == null ? void 0 : _a.startsWith("//")) ? new URL(base + request.url) : new URL(request.url || "/", base)
90
+ ),
91
+ {
92
+ method: request.method,
93
+ headers: toHeaders(headers),
94
+ body: !["HEAD", "GET"].includes((_b = request.method) != null ? _b : "") ? toReadableStream(request) : null
95
+ }
96
+ );
97
+ };
98
+ }
99
+
100
+ // src/adapter.ts
27
101
  var dependencies = {
28
102
  Headers,
29
103
  ReadableStream,
@@ -60,7 +134,7 @@ function addDuplexToInit(init) {
60
134
  return init;
61
135
  }
62
136
  function toMiddleware(webHandler, options) {
63
- const toRequest = buildToRequest(dependencies);
137
+ const toRequest = buildToRequestWithHttp2Compat(dependencies);
64
138
  const toFetchEvent = buildToFetchEvent(dependencies);
65
139
  return async function middleware(incomingMessage, serverResponse, next) {
66
140
  try {
@@ -141,7 +215,7 @@ function checkWritable(serverResponse) {
141
215
  return socket.writable;
142
216
  }
143
217
  function buildToNodeHandler(dependencies2, options) {
144
- const toRequest = buildToRequest(dependencies2);
218
+ const toRequest = buildToRequestWithHttp2Compat(dependencies2);
145
219
  const toFetchEvent = buildToFetchEvent(dependencies2);
146
220
  return function toNodeHandler(webHandler) {
147
221
  return (incomingMessage, serverResponse) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@web-widget/node",
3
3
  "description": "Node.js adapter",
4
- "version": "1.72.3",
4
+ "version": "2.1.0",
5
5
  "homepage": "https://github.com/web-widget/web-widget#readme",
6
6
  "repository": {
7
7
  "type": "git",