@wooksjs/event-http 0.7.4 → 0.7.5

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.
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
- import { EventContext, cached, cachedBy, createEventContext, current, defineEventKind, defineWook, routeParamsKey, run, slot, useEventId, useLogger, useRouteParams } from "@wooksjs/event-core";
1
+ import { EventContext, cached, cachedBy, createEventContext, current, defineEventKind, defineWook, routeParamsKey, run, slot, tryGetCurrent, useEventId, useLogger, useRouteParams } from "@wooksjs/event-core";
2
2
  import { Buffer as Buffer$1 } from "buffer";
3
3
  import { Readable, pipeline } from "node:stream";
4
4
  import { promisify } from "node:util";
5
5
  import { createBrotliCompress, createBrotliDecompress, createDeflate, createGunzip, createGzip, createInflate } from "node:zlib";
6
6
  import { URLSearchParams } from "url";
7
7
  import http, { IncomingMessage, ServerResponse } from "http";
8
+ import { Socket } from "net";
8
9
  import { WooksAdapterBase } from "wooks";
9
10
  import { Readable as Readable$1 } from "stream";
10
- import { Socket } from "net";
11
11
 
12
12
  //#region packages/event-http/src/http-kind.ts
13
13
  /** Event kind definition for HTTP requests. Provides typed context slots for `req`, `response`, and `requestLimits`. */
@@ -646,430 +646,80 @@ function useHttpContext(ctx) {
646
646
  }
647
647
 
648
648
  //#endregion
649
- //#region packages/event-http/src/errors/403.tl.svg
650
- function _403_tl_default(ctx) {
651
- return `<svg height="64" viewBox="0 4 100 96" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#888888" stroke-width="2">
652
- <path d="M50 90.625C64.4042 87.1875 83.5751 69.8667 83.5751 48.6937V24.0854L50 9.375L16.425 24.0833V48.6937C16.425 69.8667 35.5959 87.1875 50 90.625Z" fill="#ff000050">
653
- <animate attributeName="fill" dur="2s" repeatCount="indefinite"
654
- values="#ff000000;#ff000050;#ff000000" />
655
- </path>
656
-
657
- <path d="M61.5395 46.0812H38.4604C37.1061 46.0812 36.0083 47.1791 36.0083 48.5333V65.075C36.0083 66.4292 37.1061 67.5271 38.4604 67.5271H61.5395C62.8938 67.5271 63.9916 66.4292 63.9916 65.075V48.5333C63.9916 47.1791 62.8938 46.0812 61.5395 46.0812Z" />
658
-
659
- <path d="M41.7834 46.0834V39.6813C41.7834 37.5021 42.6491 35.4121 44.1901 33.8712C45.731 32.3303 47.8209 31.4646 50.0001 31.4646C52.1793 31.4646 54.2693 32.3303 55.8102 33.8712C57.3511 35.4121 58.2168 37.5021 58.2168 39.6813V46.0813" />
660
- </svg>
661
- `;
649
+ //#region packages/event-http/src/utils/time.ts
650
+ function convertTime(time, unit = "ms") {
651
+ if (typeof time === "number") return time / units[unit];
652
+ const rg = /(\d+)(\w+)/gu;
653
+ let t = 0;
654
+ let r;
655
+ while (r = rg.exec(time)) t += Number(r[1]) * (units[r[2]] || 0);
656
+ return t / units[unit];
662
657
  }
658
+ const units = {
659
+ ms: 1,
660
+ s: 1e3,
661
+ m: 1e3 * 60,
662
+ h: 1e3 * 60 * 60,
663
+ d: 1e3 * 60 * 60 * 24,
664
+ w: 1e3 * 60 * 60 * 24 * 7,
665
+ M: 1e3 * 60 * 60 * 24 * 30,
666
+ Y: 1e3 * 60 * 60 * 24 * 365
667
+ };
663
668
 
664
669
  //#endregion
665
- //#region packages/event-http/src/errors/404.tl.svg
666
- function _404_tl_default(ctx) {
667
- return `<svg height="64" viewBox="0 20 100 64" fill="none" xmlns="http://www.w3.org/2000/svg">
668
- <defs>
669
- <path id="sheet" d="M86.5 36.5V47.5H97.5V92.5H52.5V36.5H86.5ZM63 68.5H87V67.5H63V68.5ZM63 63.5H87V62.5H63V63.5ZM63 58.5H87V57.5H63V58.5ZM96.793 46.5H87.5V37.207L96.793 46.5Z" fill="#88888833" stroke="#888888aa"/>
670
- </defs>
671
-
672
- <g id="queue" transform="translate(-5 -10)">
673
- <use href="#sheet" opacity="0">
674
- <animateTransform attributeName="transform" type="translate"
675
- dur="3s" repeatCount="indefinite"
676
- keyTimes="0;0.1;0.32;0.42;1"
677
- values="30 0; -20 0; -20 0; -70 0; -70 0" />
678
- <animate attributeName="opacity"
679
- dur="3s" repeatCount="indefinite"
680
- keyTimes="0;0.1;0.32;0.42;1"
681
- values="0;1;1;0;0" />
682
- </use>
683
-
684
- <use href="#sheet" opacity="0">
685
- <animateTransform attributeName="transform" type="translate"
686
- dur="3s" begin="1s" repeatCount="indefinite"
687
- keyTimes="0;0.1;0.32;0.42;1"
688
- values="30 0; -20 0; -20 0; -70 0; -70 0" />
689
- <animate attributeName="opacity"
690
- dur="3s" begin="1s" repeatCount="indefinite"
691
- keyTimes="0;0.1;0.32;0.42;1"
692
- values="0;1;1;0;0" />
693
- </use>
694
-
695
- <use href="#sheet" opacity="0">
696
- <animateTransform attributeName="transform" type="translate"
697
- dur="3s" begin="2s" repeatCount="indefinite"
698
- keyTimes="0;0.1;0.32;0.42;1"
699
- values="30 0; -20 0; -20 0; -70 0; -70 0" />
700
- <animate attributeName="opacity"
701
- dur="3s" begin="2s" repeatCount="indefinite"
702
- keyTimes="0;0.1;0.32;0.42;1"
703
- values="0;1;1;0;0" />
704
- </use>
705
- </g>
706
-
707
- <g>
708
- <path d="M49.5 32.5C58.3366 32.5 65.5 39.6634 65.5 48.5C65.5 54.4781 62.222 59.6923 57.3584 62.4404C55.0386 63.7512 52.3591 64.5 49.5 64.5C40.6634 64.5 33.5 57.3366 33.5 48.5C33.5 39.6634 40.6634 32.5 49.5 32.5Z" fill="#ffffff50" stroke="#888888" stroke-width="3"/>
709
-
710
- <path d="M62.7101 74.5691C63.117 75.2907 64.0318 75.5459 64.7534 75.139C65.4751 74.7321 65.7302 73.8173 65.3233 73.0957L62.7101 74.5691ZM58.05 63.25L56.7434 63.9867L62.7101 74.5691L64.0167 73.8324L65.3233 73.0957L59.3567 62.5133L58.05 63.25Z" fill="#888888"/>
711
- </g>
712
- </svg>
713
-
714
- `;
670
+ //#region packages/event-http/src/utils/cache-control.ts
671
+ /** Renders a `TCacheControl` object into a `Cache-Control` header string. */
672
+ function renderCacheControl(data) {
673
+ let attrs = "";
674
+ for (const [a, v] of Object.entries(data)) {
675
+ if (v === void 0) continue;
676
+ const func = cacheControlFunc[a];
677
+ if (typeof func === "function") {
678
+ const val = func(v);
679
+ if (val) attrs += attrs ? `, ${val}` : val;
680
+ } else throw new TypeError(`Unknown Cache-Control attribute ${a}`);
681
+ }
682
+ return attrs;
715
683
  }
684
+ const cacheControlFunc = {
685
+ mustRevalidate: (v) => v ? "must-revalidate" : "",
686
+ noCache: (v) => v ? typeof v === "string" ? `no-cache="${v}"` : "no-cache" : "",
687
+ noStore: (v) => v ? "no-store" : "",
688
+ noTransform: (v) => v ? "no-transform" : "",
689
+ public: (v) => v ? "public" : "",
690
+ private: (v) => v ? typeof v === "string" ? `private="${v}"` : "private" : "",
691
+ proxyRevalidate: (v) => v ? "proxy-revalidate" : "",
692
+ maxAge: (v) => `max-age=${convertTime(v, "s").toString()}`,
693
+ sMaxage: (v) => `s-maxage=${convertTime(v, "s").toString()}`
694
+ };
716
695
 
717
696
  //#endregion
718
- //#region packages/event-http/src/errors/500.tl.svg
719
- function _500_tl_default(ctx) {
720
- return `<svg height="64" viewBox="0 0 120 100" xmlns="http://www.w3.org/2000/svg">
721
-
722
- <g id="server">
723
-
724
- <g fill="#88888888" stroke="#88888888" stroke-width="2" >
725
- <path d="M18 90C13.5817 90 10 86.4182 10 82V38C10 33.5817 13.5817 30 18 30H50.5L58 43L52.5 53L56 68.5L49.0098 89.97L61.2141 71.4358L58.363 54.315L64.7769 43.5511L58.2763 30.2943L104.243 32.0434C108.658 32.2114 112.101 35.9267 111.933 40.3418L110.26 84.31C110.092 88.725 106.377 92.168 101.962 92L49 90H18Z" />
726
- </g>
727
- <circle cx="30" cy="60" r="6" fill="red">
728
- <animate attributeName="fill" dur="0.8s"
729
- values="red;#2d0000;red" repeatCount="indefinite"/>
730
- </circle>
731
-
732
- </g>
733
-
734
- <g fill="lightgray" opacity="0.75">
735
- <circle cx="50" cy="35" r="6">
736
- <animate attributeName="cy" from="35" to="15" dur="2s"
737
- repeatCount="indefinite"/>
738
- <animate attributeName="opacity" values="0.75;0" dur="2s"
739
- repeatCount="indefinite"/>
740
- </circle>
741
- <circle cx="60" cy="40" r="4">
742
- <animate attributeName="cy" from="40" to="20" dur="2s"
743
- begin="0.4s" repeatCount="indefinite"/>
744
- <animate attributeName="opacity" values="0.75;0" dur="2s"
745
- begin="0.4s" repeatCount="indefinite"/>
746
- </circle>
747
- </g>
748
-
749
- </svg>
750
- `;
697
+ //#region packages/event-http/src/utils/set-cookie.ts
698
+ const COOKIE_NAME_RE = /^[\w!#$%&'*+\-.^`|~]+$/;
699
+ function sanitizeCookieAttrValue(v) {
700
+ return v.replace(/[;\r\n]/g, "");
751
701
  }
752
-
753
- //#endregion
754
- //#region packages/event-http/src/errors/error.tl.html
755
- function error_tl_default(ctx) {
756
- const { statusCode, statusMessage, icon, message, details, link, image, version } = ctx;
757
- return `<!doctype html>
758
- <html lang="en">
759
- <head>
760
- <meta charset="UTF-8" />
761
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
762
- <title>${statusCode} ${statusMessage}</title>
763
- <style>
764
- body {
765
- font-family:
766
- -apple-system, BlinkMacMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
767
- 'Open Sans', 'Helvetica Neue', sans-serif;
768
- display: flex;
769
- justify-content: center;
770
- align-items: flex-start;
771
- min-height: 100vh;
772
- margin: 0;
773
- padding: 0 20px;
774
- box-sizing: border-box;
775
- transition:
776
- background-color 0.3s ease,
777
- color 0.3s ease;
778
- }
779
-
780
- .error-container {
781
- padding: 48px;
782
- padding-bottom: 12px !important;
783
- background-color: #ffffff;
784
- border-radius: 0 0 12px 12px;
785
- box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
786
- text-align: center;
787
- max-width: 650px;
788
- width: 100%;
789
- transition:
790
- background-color 0.3s ease,
791
- border-color 0.3s ease,
792
- box-shadow 0.3s ease;
793
- }
794
-
795
- .status-code {
796
- font-size: 5rem;
797
- font-weight: 900;
798
- margin-bottom: 5px;
799
- line-height: 1;
800
- transition: color 0.3s ease;
801
- display: flex;
802
- align-items: center;
803
- justify-content: center;
804
- gap: 1rem;
805
- position: relative;
806
- margin-right: 24px;
807
- }
808
-
809
- .status-text {
810
- font-size: 2.25rem;
811
- font-weight: 700;
812
- margin-bottom: 25px;
813
- transition: color 0.3s ease;
814
- }
815
-
816
- .error-message {
817
- font-size: 1.25rem;
818
- margin-bottom: 40px;
819
- line-height: 1.7;
820
- transition: color 0.3s ease;
821
- }
822
-
823
- .json-details-container {
824
- padding: 20px;
825
- border-radius: 8px;
826
- text-align: left;
827
- overflow-x: auto;
828
- font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
829
- font-size: 0.9rem;
830
- border: 1px solid;
831
- transition:
832
- background-color 0.3s ease,
833
- color 0.3s ease,
834
- border-color 0.3s ease;
835
- }
836
-
837
- .json-details-container pre {
838
- margin: 0;
839
- white-space: pre-wrap;
840
- word-break: break-all;
841
- }
842
-
843
- .json-details-container code {
844
- display: block;
845
- }
846
-
847
- body {
848
- background-color: #f8fafc;
849
- color: #1f2937;
850
- }
851
- .error-container {
852
- background-color: #ffffff;
853
- box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
854
- }
855
- .status-code {
856
- color: #dc2626;
857
- }
858
- .status-text {
859
- color: #1f2937;
860
- }
861
- .error-message {
862
- color: #4b5563;
863
- }
864
- .json-details-container {
865
- background-color: #f0f4f8;
866
- color: #374151;
867
- border-color: #d1d5db;
868
- }
869
- .json-details-container p {
870
- color: #6b7280;
871
- }
872
-
873
- @media (prefers-color-scheme: dark) {
874
- body {
875
- background-color: #2d3748;
876
- color: #e2e8f0;
877
- }
878
- .error-container {
879
- background-color: #1a202c;
880
- box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
881
- }
882
- .status-code {
883
- color: #f56565;
884
- }
885
- .status-text {
886
- color: #cbd5e1;
887
- }
888
- .error-message {
889
- color: #a0aec0;
890
- }
891
- .json-details-container {
892
- background-color: #2d3748;
893
- color: #e2e8f0;
894
- border-color: #4a5568;
895
- }
896
- .json-details-container p {
897
- color: #a0aec0;
898
- }
899
- }
900
-
901
- .footer {
902
- display: flex;
903
- gap: 0.25rem;
904
- font-size: 0.6em;
905
- justify-content: flex-end;
906
- align-items: center;
907
- margin-top: 12px;
908
- opacity: 0.5;
909
- transition: 0.25s ease-in-out;
910
- }
911
-
912
- .footer img {
913
- filter: grayscale(0.5);
914
- transition: 0.25s ease-in-out;
915
- }
916
-
917
- .footer:hover {
918
- opacity: 1;
919
- }
920
- .footer:hover img {
921
- filter: grayscale(0);
922
- }
923
-
924
- @media (max-width: 768px) {
925
- body {
926
- padding: 15px;
927
- }
928
- .error-container {
929
- padding: 32px;
930
- }
931
- .status-code {
932
- font-size: 4rem;
933
- }
934
- .status-text {
935
- font-size: 1.8rem;
936
- }
937
- .error-message {
938
- font-size: 1.1rem;
939
- margin-bottom: 30px;
940
- }
941
- .json-details-container {
942
- font-size: 0.85rem;
943
- }
944
- }
945
-
946
- @media (max-width: 480px) {
947
- body {
948
- padding: 10px;
949
- }
950
- .error-container {
951
- padding: 24px;
952
- border-radius: 8px;
953
- }
954
- .status-code {
955
- font-size: 3rem;
956
- }
957
- .status-text {
958
- font-size: 1.5rem;
959
- margin-bottom: 20px;
960
- }
961
- .error-message {
962
- font-size: 1rem;
963
- margin-bottom: 25px;
964
- }
965
- .json-details-container {
966
- padding: 15px;
967
- font-size: 0.8rem;
968
- }
969
- }
970
- </style>
971
- </head>
972
- <body>
973
- <div class="error-container">
974
- <div id="statusCode" class="status-code">${icon} ${statusCode}</div>
975
-
976
- <div id="statusText" class="status-text">${statusMessage}</div>
977
-
978
- <p id="errorMessage" class="error-message">${message}</p>
979
-
980
- <!-- prettier-ignore -->
981
- <div class="json-details-container"style="display: ${details ? "block" : "none"};">
982
- <p class="text-sm">Technical Details:</p>
983
- <pre><code id="jsonDetails">${details}</code></pre>
984
- </div>
985
- <div class="footer">
986
- Powered by
987
- <a href="${link}" target="_blank">
988
- <img height="20" alt="%{poweredBy}" src="${image}" />
989
- </a>
990
- v${version}
991
- </div>
992
- </div>
993
- </body>
994
- </html>
995
- `;
996
- }
997
-
998
- //#endregion
999
- //#region packages/event-http/src/utils/time.ts
1000
- function convertTime(time, unit = "ms") {
1001
- if (typeof time === "number") return time / units[unit];
1002
- const rg = /(\d+)(\w+)/gu;
1003
- let t = 0;
1004
- let r;
1005
- while (r = rg.exec(time)) t += Number(r[1]) * (units[r[2]] || 0);
1006
- return t / units[unit];
1007
- }
1008
- const units = {
1009
- ms: 1,
1010
- s: 1e3,
1011
- m: 1e3 * 60,
1012
- h: 1e3 * 60 * 60,
1013
- d: 1e3 * 60 * 60 * 24,
1014
- w: 1e3 * 60 * 60 * 24 * 7,
1015
- M: 1e3 * 60 * 60 * 24 * 30,
1016
- Y: 1e3 * 60 * 60 * 24 * 365
1017
- };
1018
-
1019
- //#endregion
1020
- //#region packages/event-http/src/utils/cache-control.ts
1021
- /** Renders a `TCacheControl` object into a `Cache-Control` header string. */
1022
- function renderCacheControl(data) {
1023
- let attrs = "";
1024
- for (const [a, v] of Object.entries(data)) {
1025
- if (v === void 0) continue;
1026
- const func = cacheControlFunc[a];
1027
- if (typeof func === "function") {
1028
- const val = func(v);
1029
- if (val) attrs += attrs ? `, ${val}` : val;
1030
- } else throw new TypeError(`Unknown Cache-Control attribute ${a}`);
1031
- }
1032
- return attrs;
1033
- }
1034
- const cacheControlFunc = {
1035
- mustRevalidate: (v) => v ? "must-revalidate" : "",
1036
- noCache: (v) => v ? typeof v === "string" ? `no-cache="${v}"` : "no-cache" : "",
1037
- noStore: (v) => v ? "no-store" : "",
1038
- noTransform: (v) => v ? "no-transform" : "",
1039
- public: (v) => v ? "public" : "",
1040
- private: (v) => v ? typeof v === "string" ? `private="${v}"` : "private" : "",
1041
- proxyRevalidate: (v) => v ? "proxy-revalidate" : "",
1042
- maxAge: (v) => `max-age=${convertTime(v, "s").toString()}`,
1043
- sMaxage: (v) => `s-maxage=${convertTime(v, "s").toString()}`
1044
- };
1045
-
1046
- //#endregion
1047
- //#region packages/event-http/src/utils/set-cookie.ts
1048
- const COOKIE_NAME_RE = /^[\w!#$%&'*+\-.^`|~]+$/;
1049
- function sanitizeCookieAttrValue(v) {
1050
- return v.replace(/[;\r\n]/g, "");
1051
- }
1052
- function renderCookie(key, data) {
1053
- if (!COOKIE_NAME_RE.test(key)) throw new TypeError(`Invalid cookie name "${key}"`);
1054
- let attrs = "";
1055
- for (const [a, v] of Object.entries(data.attrs)) {
1056
- const func = cookieAttrFunc[a];
1057
- if (typeof func === "function") {
1058
- const val = func(v);
1059
- attrs += val ? `; ${val}` : "";
1060
- } else throw new TypeError(`Unknown Set-Cookie attribute ${a}`);
1061
- }
1062
- return `${key}=${encodeURIComponent(data.value)}${attrs}`;
1063
- }
1064
- const cookieAttrFunc = {
1065
- expires: (v) => `Expires=${typeof v === "string" || typeof v === "number" ? new Date(v).toUTCString() : v.toUTCString()}`,
1066
- maxAge: (v) => `Max-Age=${convertTime(v, "s").toString()}`,
1067
- domain: (v) => `Domain=${sanitizeCookieAttrValue(String(v))}`,
1068
- path: (v) => `Path=${sanitizeCookieAttrValue(String(v))}`,
1069
- secure: (v) => v ? "Secure" : "",
1070
- httpOnly: (v) => v ? "HttpOnly" : "",
1071
- sameSite: (v) => v ? `SameSite=${typeof v === "string" ? v : "Strict"}` : ""
1072
- };
702
+ function renderCookie(key, data) {
703
+ if (!COOKIE_NAME_RE.test(key)) throw new TypeError(`Invalid cookie name "${key}"`);
704
+ let attrs = "";
705
+ for (const [a, v] of Object.entries(data.attrs)) {
706
+ const func = cookieAttrFunc[a];
707
+ if (typeof func === "function") {
708
+ const val = func(v);
709
+ attrs += val ? `; ${val}` : "";
710
+ } else throw new TypeError(`Unknown Set-Cookie attribute ${a}`);
711
+ }
712
+ return `${key}=${encodeURIComponent(data.value)}${attrs}`;
713
+ }
714
+ const cookieAttrFunc = {
715
+ expires: (v) => `Expires=${typeof v === "string" || typeof v === "number" ? new Date(v).toUTCString() : v.toUTCString()}`,
716
+ maxAge: (v) => `Max-Age=${convertTime(v, "s").toString()}`,
717
+ domain: (v) => `Domain=${sanitizeCookieAttrValue(String(v))}`,
718
+ path: (v) => `Path=${sanitizeCookieAttrValue(String(v))}`,
719
+ secure: (v) => v ? "Secure" : "",
720
+ httpOnly: (v) => v ? "HttpOnly" : "",
721
+ sameSite: (v) => v ? `SameSite=${typeof v === "string" ? v : "Strict"}` : ""
722
+ };
1073
723
 
1074
724
  //#endregion
1075
725
  //#region packages/event-http/src/response/http-response.ts
@@ -1101,10 +751,11 @@ var HttpResponse = class {
1101
751
  * @param _logger - Logger instance for error reporting.
1102
752
  * @param defaultHeaders - Optional headers to pre-populate on this response (e.g. from `securityHeaders()`).
1103
753
  */
1104
- constructor(_res, _req, _logger, defaultHeaders) {
754
+ constructor(_res, _req, _logger, defaultHeaders, _captureMode = false) {
1105
755
  this._res = _res;
1106
756
  this._req = _req;
1107
757
  this._logger = _logger;
758
+ this._captureMode = _captureMode;
1108
759
  if (defaultHeaders) for (const key in defaultHeaders) this._headers[key] = defaultHeaders[key];
1109
760
  }
1110
761
  _status = 0;
@@ -1238,6 +889,53 @@ var HttpResponse = class {
1238
889
  get responded() {
1239
890
  return this._responded || !this._res.writable || this._res.writableEnded;
1240
891
  }
892
+ /**
893
+ * Builds a Web Standard `Response` from the accumulated response state
894
+ * (status, headers, cookies, body) without writing to the underlying `ServerResponse`.
895
+ *
896
+ * Used by `WooksHttp.fetch()` for programmatic invocation.
897
+ */
898
+ toWebResponse() {
899
+ this.finalizeCookies();
900
+ const body = this._body;
901
+ const method = this._req.method;
902
+ if (body instanceof Readable$1) {
903
+ this.autoStatus(true);
904
+ return new globalThis.Response(method === "HEAD" ? null : Readable$1.toWeb(body), {
905
+ status: this._status,
906
+ headers: this._buildWebHeaders()
907
+ });
908
+ }
909
+ if (hasFetchResponse && body instanceof globalThis.Response) {
910
+ this._status = this._status || body.status;
911
+ body.headers.forEach((v, k) => {
912
+ if (!this._headers[k]) this._headers[k] = v;
913
+ });
914
+ return new globalThis.Response(method === "HEAD" ? null : body.body, {
915
+ status: this._status,
916
+ headers: this._buildWebHeaders()
917
+ });
918
+ }
919
+ const rendered = this.renderBody();
920
+ this.autoStatus(!!rendered);
921
+ if (rendered) {
922
+ const contentLength = typeof rendered === "string" ? Buffer.byteLength(rendered) : rendered.byteLength;
923
+ this._headers["content-length"] = contentLength.toString();
924
+ }
925
+ const webResponse = new globalThis.Response(method === "HEAD" ? null : rendered || null, {
926
+ status: this._status,
927
+ headers: this._buildWebHeaders()
928
+ });
929
+ if (typeof rendered === "string" && rendered) webResponse.text = () => Promise.resolve(rendered);
930
+ if (typeof body === "object" && body !== null && !(body instanceof Uint8Array) && !(body instanceof Readable$1) && !(hasFetchResponse && body instanceof globalThis.Response)) {
931
+ const original = body;
932
+ webResponse.json = () => Promise.resolve(original);
933
+ }
934
+ return webResponse;
935
+ }
936
+ _buildWebHeaders() {
937
+ return recordToWebHeaders(this._headers);
938
+ }
1241
939
  renderBody() {
1242
940
  const body = this._body;
1243
941
  if (body === void 0 || body === null) return "";
@@ -1282,6 +980,10 @@ var HttpResponse = class {
1282
980
  throw err;
1283
981
  }
1284
982
  this._responded = true;
983
+ if (this._captureMode) {
984
+ this.finalizeCookies();
985
+ return;
986
+ }
1285
987
  this.finalizeCookies();
1286
988
  const body = this._body;
1287
989
  const method = this._req.method;
@@ -1300,6 +1002,7 @@ var HttpResponse = class {
1300
1002
  if (existing) this._headers["set-cookie"] = [...Array.isArray(existing) ? existing : [existing], ...rendered];
1301
1003
  else this._headers["set-cookie"] = rendered;
1302
1004
  }
1005
+ this._hasCookies = false;
1303
1006
  }
1304
1007
  autoStatus(hasBody) {
1305
1008
  if (this._status) return;
@@ -1361,11 +1064,368 @@ var HttpResponse = class {
1361
1064
  this._res.writeHead(this._status, this._headers).end(method === "HEAD" ? "" : renderedBody);
1362
1065
  }
1363
1066
  };
1067
+ /** Converts a Record of headers to a Web Standard `Headers` object. */
1068
+ function recordToWebHeaders(record) {
1069
+ const headers = new Headers();
1070
+ for (const [key, value] of Object.entries(record)) if (Array.isArray(value)) for (const v of value) headers.append(key, v);
1071
+ else if (value) headers.set(key, value);
1072
+ return headers;
1073
+ }
1074
+
1075
+ //#endregion
1076
+ //#region packages/event-http/src/errors/403.tl.svg
1077
+ function _403_tl_default(ctx) {
1078
+ return `<svg height="64" viewBox="0 4 100 96" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#888888" stroke-width="2">
1079
+ <path d="M50 90.625C64.4042 87.1875 83.5751 69.8667 83.5751 48.6937V24.0854L50 9.375L16.425 24.0833V48.6937C16.425 69.8667 35.5959 87.1875 50 90.625Z" fill="#ff000050">
1080
+ <animate attributeName="fill" dur="2s" repeatCount="indefinite"
1081
+ values="#ff000000;#ff000050;#ff000000" />
1082
+ </path>
1083
+
1084
+ <path d="M61.5395 46.0812H38.4604C37.1061 46.0812 36.0083 47.1791 36.0083 48.5333V65.075C36.0083 66.4292 37.1061 67.5271 38.4604 67.5271H61.5395C62.8938 67.5271 63.9916 66.4292 63.9916 65.075V48.5333C63.9916 47.1791 62.8938 46.0812 61.5395 46.0812Z" />
1085
+
1086
+ <path d="M41.7834 46.0834V39.6813C41.7834 37.5021 42.6491 35.4121 44.1901 33.8712C45.731 32.3303 47.8209 31.4646 50.0001 31.4646C52.1793 31.4646 54.2693 32.3303 55.8102 33.8712C57.3511 35.4121 58.2168 37.5021 58.2168 39.6813V46.0813" />
1087
+ </svg>
1088
+ `;
1089
+ }
1090
+
1091
+ //#endregion
1092
+ //#region packages/event-http/src/errors/404.tl.svg
1093
+ function _404_tl_default(ctx) {
1094
+ return `<svg height="64" viewBox="0 20 100 64" fill="none" xmlns="http://www.w3.org/2000/svg">
1095
+ <defs>
1096
+ <path id="sheet" d="M86.5 36.5V47.5H97.5V92.5H52.5V36.5H86.5ZM63 68.5H87V67.5H63V68.5ZM63 63.5H87V62.5H63V63.5ZM63 58.5H87V57.5H63V58.5ZM96.793 46.5H87.5V37.207L96.793 46.5Z" fill="#88888833" stroke="#888888aa"/>
1097
+ </defs>
1098
+
1099
+ <g id="queue" transform="translate(-5 -10)">
1100
+ <use href="#sheet" opacity="0">
1101
+ <animateTransform attributeName="transform" type="translate"
1102
+ dur="3s" repeatCount="indefinite"
1103
+ keyTimes="0;0.1;0.32;0.42;1"
1104
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
1105
+ <animate attributeName="opacity"
1106
+ dur="3s" repeatCount="indefinite"
1107
+ keyTimes="0;0.1;0.32;0.42;1"
1108
+ values="0;1;1;0;0" />
1109
+ </use>
1110
+
1111
+ <use href="#sheet" opacity="0">
1112
+ <animateTransform attributeName="transform" type="translate"
1113
+ dur="3s" begin="1s" repeatCount="indefinite"
1114
+ keyTimes="0;0.1;0.32;0.42;1"
1115
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
1116
+ <animate attributeName="opacity"
1117
+ dur="3s" begin="1s" repeatCount="indefinite"
1118
+ keyTimes="0;0.1;0.32;0.42;1"
1119
+ values="0;1;1;0;0" />
1120
+ </use>
1121
+
1122
+ <use href="#sheet" opacity="0">
1123
+ <animateTransform attributeName="transform" type="translate"
1124
+ dur="3s" begin="2s" repeatCount="indefinite"
1125
+ keyTimes="0;0.1;0.32;0.42;1"
1126
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
1127
+ <animate attributeName="opacity"
1128
+ dur="3s" begin="2s" repeatCount="indefinite"
1129
+ keyTimes="0;0.1;0.32;0.42;1"
1130
+ values="0;1;1;0;0" />
1131
+ </use>
1132
+ </g>
1133
+
1134
+ <g>
1135
+ <path d="M49.5 32.5C58.3366 32.5 65.5 39.6634 65.5 48.5C65.5 54.4781 62.222 59.6923 57.3584 62.4404C55.0386 63.7512 52.3591 64.5 49.5 64.5C40.6634 64.5 33.5 57.3366 33.5 48.5C33.5 39.6634 40.6634 32.5 49.5 32.5Z" fill="#ffffff50" stroke="#888888" stroke-width="3"/>
1136
+
1137
+ <path d="M62.7101 74.5691C63.117 75.2907 64.0318 75.5459 64.7534 75.139C65.4751 74.7321 65.7302 73.8173 65.3233 73.0957L62.7101 74.5691ZM58.05 63.25L56.7434 63.9867L62.7101 74.5691L64.0167 73.8324L65.3233 73.0957L59.3567 62.5133L58.05 63.25Z" fill="#888888"/>
1138
+ </g>
1139
+ </svg>
1140
+
1141
+ `;
1142
+ }
1143
+
1144
+ //#endregion
1145
+ //#region packages/event-http/src/errors/500.tl.svg
1146
+ function _500_tl_default(ctx) {
1147
+ return `<svg height="64" viewBox="0 0 120 100" xmlns="http://www.w3.org/2000/svg">
1148
+
1149
+ <g id="server">
1150
+
1151
+ <g fill="#88888888" stroke="#88888888" stroke-width="2" >
1152
+ <path d="M18 90C13.5817 90 10 86.4182 10 82V38C10 33.5817 13.5817 30 18 30H50.5L58 43L52.5 53L56 68.5L49.0098 89.97L61.2141 71.4358L58.363 54.315L64.7769 43.5511L58.2763 30.2943L104.243 32.0434C108.658 32.2114 112.101 35.9267 111.933 40.3418L110.26 84.31C110.092 88.725 106.377 92.168 101.962 92L49 90H18Z" />
1153
+ </g>
1154
+ <circle cx="30" cy="60" r="6" fill="red">
1155
+ <animate attributeName="fill" dur="0.8s"
1156
+ values="red;#2d0000;red" repeatCount="indefinite"/>
1157
+ </circle>
1158
+
1159
+ </g>
1160
+
1161
+ <g fill="lightgray" opacity="0.75">
1162
+ <circle cx="50" cy="35" r="6">
1163
+ <animate attributeName="cy" from="35" to="15" dur="2s"
1164
+ repeatCount="indefinite"/>
1165
+ <animate attributeName="opacity" values="0.75;0" dur="2s"
1166
+ repeatCount="indefinite"/>
1167
+ </circle>
1168
+ <circle cx="60" cy="40" r="4">
1169
+ <animate attributeName="cy" from="40" to="20" dur="2s"
1170
+ begin="0.4s" repeatCount="indefinite"/>
1171
+ <animate attributeName="opacity" values="0.75;0" dur="2s"
1172
+ begin="0.4s" repeatCount="indefinite"/>
1173
+ </circle>
1174
+ </g>
1175
+
1176
+ </svg>
1177
+ `;
1178
+ }
1179
+
1180
+ //#endregion
1181
+ //#region packages/event-http/src/errors/error.tl.html
1182
+ function error_tl_default(ctx) {
1183
+ const { statusCode, statusMessage, icon, message, details, link, image, version } = ctx;
1184
+ return `<!doctype html>
1185
+ <html lang="en">
1186
+ <head>
1187
+ <meta charset="UTF-8" />
1188
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
1189
+ <title>${statusCode} ${statusMessage}</title>
1190
+ <style>
1191
+ body {
1192
+ font-family:
1193
+ -apple-system, BlinkMacMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
1194
+ 'Open Sans', 'Helvetica Neue', sans-serif;
1195
+ display: flex;
1196
+ justify-content: center;
1197
+ align-items: flex-start;
1198
+ min-height: 100vh;
1199
+ margin: 0;
1200
+ padding: 0 20px;
1201
+ box-sizing: border-box;
1202
+ transition:
1203
+ background-color 0.3s ease,
1204
+ color 0.3s ease;
1205
+ }
1206
+
1207
+ .error-container {
1208
+ padding: 48px;
1209
+ padding-bottom: 12px !important;
1210
+ background-color: #ffffff;
1211
+ border-radius: 0 0 12px 12px;
1212
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
1213
+ text-align: center;
1214
+ max-width: 650px;
1215
+ width: 100%;
1216
+ transition:
1217
+ background-color 0.3s ease,
1218
+ border-color 0.3s ease,
1219
+ box-shadow 0.3s ease;
1220
+ }
1221
+
1222
+ .status-code {
1223
+ font-size: 5rem;
1224
+ font-weight: 900;
1225
+ margin-bottom: 5px;
1226
+ line-height: 1;
1227
+ transition: color 0.3s ease;
1228
+ display: flex;
1229
+ align-items: center;
1230
+ justify-content: center;
1231
+ gap: 1rem;
1232
+ position: relative;
1233
+ margin-right: 24px;
1234
+ }
1235
+
1236
+ .status-text {
1237
+ font-size: 2.25rem;
1238
+ font-weight: 700;
1239
+ margin-bottom: 25px;
1240
+ transition: color 0.3s ease;
1241
+ }
1242
+
1243
+ .error-message {
1244
+ font-size: 1.25rem;
1245
+ margin-bottom: 40px;
1246
+ line-height: 1.7;
1247
+ transition: color 0.3s ease;
1248
+ }
1249
+
1250
+ .json-details-container {
1251
+ padding: 20px;
1252
+ border-radius: 8px;
1253
+ text-align: left;
1254
+ overflow-x: auto;
1255
+ font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
1256
+ font-size: 0.9rem;
1257
+ border: 1px solid;
1258
+ transition:
1259
+ background-color 0.3s ease,
1260
+ color 0.3s ease,
1261
+ border-color 0.3s ease;
1262
+ }
1263
+
1264
+ .json-details-container pre {
1265
+ margin: 0;
1266
+ white-space: pre-wrap;
1267
+ word-break: break-all;
1268
+ }
1269
+
1270
+ .json-details-container code {
1271
+ display: block;
1272
+ }
1273
+
1274
+ body {
1275
+ background-color: #f8fafc;
1276
+ color: #1f2937;
1277
+ }
1278
+ .error-container {
1279
+ background-color: #ffffff;
1280
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
1281
+ }
1282
+ .status-code {
1283
+ color: #dc2626;
1284
+ }
1285
+ .status-text {
1286
+ color: #1f2937;
1287
+ }
1288
+ .error-message {
1289
+ color: #4b5563;
1290
+ }
1291
+ .json-details-container {
1292
+ background-color: #f0f4f8;
1293
+ color: #374151;
1294
+ border-color: #d1d5db;
1295
+ }
1296
+ .json-details-container p {
1297
+ color: #6b7280;
1298
+ }
1299
+
1300
+ @media (prefers-color-scheme: dark) {
1301
+ body {
1302
+ background-color: #2d3748;
1303
+ color: #e2e8f0;
1304
+ }
1305
+ .error-container {
1306
+ background-color: #1a202c;
1307
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
1308
+ }
1309
+ .status-code {
1310
+ color: #f56565;
1311
+ }
1312
+ .status-text {
1313
+ color: #cbd5e1;
1314
+ }
1315
+ .error-message {
1316
+ color: #a0aec0;
1317
+ }
1318
+ .json-details-container {
1319
+ background-color: #2d3748;
1320
+ color: #e2e8f0;
1321
+ border-color: #4a5568;
1322
+ }
1323
+ .json-details-container p {
1324
+ color: #a0aec0;
1325
+ }
1326
+ }
1327
+
1328
+ .footer {
1329
+ display: flex;
1330
+ gap: 0.25rem;
1331
+ font-size: 0.6em;
1332
+ justify-content: flex-end;
1333
+ align-items: center;
1334
+ margin-top: 12px;
1335
+ opacity: 0.5;
1336
+ transition: 0.25s ease-in-out;
1337
+ }
1338
+
1339
+ .footer img {
1340
+ filter: grayscale(0.5);
1341
+ transition: 0.25s ease-in-out;
1342
+ }
1343
+
1344
+ .footer:hover {
1345
+ opacity: 1;
1346
+ }
1347
+ .footer:hover img {
1348
+ filter: grayscale(0);
1349
+ }
1350
+
1351
+ @media (max-width: 768px) {
1352
+ body {
1353
+ padding: 15px;
1354
+ }
1355
+ .error-container {
1356
+ padding: 32px;
1357
+ }
1358
+ .status-code {
1359
+ font-size: 4rem;
1360
+ }
1361
+ .status-text {
1362
+ font-size: 1.8rem;
1363
+ }
1364
+ .error-message {
1365
+ font-size: 1.1rem;
1366
+ margin-bottom: 30px;
1367
+ }
1368
+ .json-details-container {
1369
+ font-size: 0.85rem;
1370
+ }
1371
+ }
1372
+
1373
+ @media (max-width: 480px) {
1374
+ body {
1375
+ padding: 10px;
1376
+ }
1377
+ .error-container {
1378
+ padding: 24px;
1379
+ border-radius: 8px;
1380
+ }
1381
+ .status-code {
1382
+ font-size: 3rem;
1383
+ }
1384
+ .status-text {
1385
+ font-size: 1.5rem;
1386
+ margin-bottom: 20px;
1387
+ }
1388
+ .error-message {
1389
+ font-size: 1rem;
1390
+ margin-bottom: 25px;
1391
+ }
1392
+ .json-details-container {
1393
+ padding: 15px;
1394
+ font-size: 0.8rem;
1395
+ }
1396
+ }
1397
+ </style>
1398
+ </head>
1399
+ <body>
1400
+ <div class="error-container">
1401
+ <div id="statusCode" class="status-code">${icon} ${statusCode}</div>
1402
+
1403
+ <div id="statusText" class="status-text">${statusMessage}</div>
1404
+
1405
+ <p id="errorMessage" class="error-message">${message}</p>
1406
+
1407
+ <!-- prettier-ignore -->
1408
+ <div class="json-details-container"style="display: ${details ? "block" : "none"};">
1409
+ <p class="text-sm">Technical Details:</p>
1410
+ <pre><code id="jsonDetails">${details}</code></pre>
1411
+ </div>
1412
+ <div class="footer">
1413
+ Powered by
1414
+ <a href="${link}" target="_blank">
1415
+ <img height="20" alt="%{poweredBy}" src="${image}" />
1416
+ </a>
1417
+ v${version}
1418
+ </div>
1419
+ </div>
1420
+ </body>
1421
+ </html>
1422
+ `;
1423
+ }
1364
1424
 
1365
1425
  //#endregion
1366
1426
  //#region packages/event-http/src/response/wooks-http-response.ts
1367
1427
  let framework = {
1368
- version: "0.7.3",
1428
+ version: "0.7.4",
1369
1429
  poweredBy: "wooksjs",
1370
1430
  link: "https://wooks.moost.org/",
1371
1431
  image: "https://wooks.moost.org/wooks-full-logo.svg"
@@ -1436,6 +1496,13 @@ function renderErrorText(data) {
1436
1496
 
1437
1497
  //#endregion
1438
1498
  //#region packages/event-http/src/http-adapter.ts
1499
+ const DEFAULT_FORWARD_HEADERS = [
1500
+ "authorization",
1501
+ "cookie",
1502
+ "accept-language",
1503
+ "x-forwarded-for",
1504
+ "x-request-id"
1505
+ ];
1439
1506
  /** HTTP adapter for Wooks that provides route registration, server lifecycle, and request handling. */
1440
1507
  var WooksHttp = class extends WooksAdapterBase {
1441
1508
  logger;
@@ -1697,7 +1764,127 @@ var WooksHttp = class extends WooksAdapterBase {
1697
1764
  }
1698
1765
  }
1699
1766
  }
1767
+ /**
1768
+ * Programmatic route invocation using the Web Standard fetch API.
1769
+ * Goes through the full dispatch pipeline: context creation, route matching,
1770
+ * handler execution, response finalization.
1771
+ *
1772
+ * When called from within an existing HTTP context (e.g. during SSR),
1773
+ * identity headers (authorization, cookie) are automatically forwarded
1774
+ * from the calling request unless already present on the given Request.
1775
+ *
1776
+ * @param request - A Web Standard Request object.
1777
+ * @returns A Web Standard Response.
1778
+ */
1779
+ async fetch(request) {
1780
+ const url = new URL(request.url);
1781
+ const method = request.method;
1782
+ const pathname = url.pathname + url.search;
1783
+ const callerCtx = tryGetCurrent();
1784
+ let callerReq;
1785
+ if (callerCtx) try {
1786
+ callerReq = callerCtx.get(httpKind.keys.req);
1787
+ } catch {}
1788
+ const fakeReq = createFakeIncomingMessage(request, pathname, callerReq, this.opts?.forwardHeaders);
1789
+ const fakeRes = new ServerResponse(fakeReq);
1790
+ const rawChunks = [];
1791
+ const rawHeaders = {};
1792
+ let rawStatusCode = 0;
1793
+ fakeRes.writeHead = (...args) => {
1794
+ rawStatusCode = args[0];
1795
+ for (const arg of args) if (typeof arg === "object" && arg !== null) for (const [k, v] of Object.entries(arg)) rawHeaders[k] = v;
1796
+ return fakeRes;
1797
+ };
1798
+ fakeRes.write = (chunk, ...args) => {
1799
+ if (chunk !== null && chunk !== void 0) rawChunks.push(typeof chunk === "string" ? Buffer$1.from(chunk) : chunk);
1800
+ const cb = args.find((a) => typeof a === "function");
1801
+ if (cb) cb();
1802
+ return true;
1803
+ };
1804
+ fakeRes.end = (chunk, ...args) => {
1805
+ if (chunk !== null && chunk !== void 0 && typeof chunk !== "function") rawChunks.push(typeof chunk === "string" ? Buffer$1.from(chunk) : chunk);
1806
+ const cb = args.find((a) => typeof a === "function");
1807
+ if (cb) cb();
1808
+ return fakeRes;
1809
+ };
1810
+ const response = new this.ResponseClass(fakeRes, fakeReq, this.logger, this.opts?.defaultHeaders, true);
1811
+ let bodyBuffer;
1812
+ if (request.body) bodyBuffer = Buffer$1.from(await request.bytes());
1813
+ const ctxOptions = this.eventContextOptions;
1814
+ const requestLimits = this.opts?.requestLimits;
1815
+ const notFoundHandler = this.opts?.onNotFound;
1816
+ return createHttpContext(ctxOptions, {
1817
+ req: fakeReq,
1818
+ response,
1819
+ requestLimits
1820
+ }, async () => {
1821
+ const ctx = current();
1822
+ if (bodyBuffer) ctx.set(rawBodySlot, Promise.resolve(bodyBuffer));
1823
+ try {
1824
+ const handlers = this.wooks.lookupHandlers(method, pathname, ctx);
1825
+ if (handlers || notFoundHandler) {
1826
+ const result = this.processHandlers(handlers || [notFoundHandler], ctx, response);
1827
+ if (result !== null && result !== void 0 && typeof result.then === "function") await result.catch((error) => {
1828
+ if (!response.responded) this.respond(error, response, ctx);
1829
+ });
1830
+ } else {
1831
+ const error = new HttpError(404);
1832
+ this.respond(error, response, ctx);
1833
+ }
1834
+ } finally {
1835
+ fakeReq.emit("end");
1836
+ fakeReq.emit("close");
1837
+ }
1838
+ let webResponse;
1839
+ if (rawChunks.length > 0 || rawStatusCode > 0) {
1840
+ const body = Buffer$1.concat(rawChunks);
1841
+ webResponse = new Response(body.length > 0 ? body : null, {
1842
+ status: rawStatusCode || 200,
1843
+ headers: recordToWebHeaders(rawHeaders)
1844
+ });
1845
+ } else webResponse = response.toWebResponse();
1846
+ if (callerReq) try {
1847
+ const parentResponse = callerCtx?.get(httpKind.keys.response);
1848
+ if (parentResponse) for (const cookie of webResponse.headers.getSetCookie()) parentResponse.setCookieRaw(cookie);
1849
+ } catch {}
1850
+ fakeReq.destroy();
1851
+ fakeRes.destroy();
1852
+ return webResponse;
1853
+ });
1854
+ }
1855
+ /**
1856
+ * Convenience wrapper for programmatic route invocation.
1857
+ * Accepts a URL string (relative paths auto-prefixed with `http://localhost`),
1858
+ * URL object, or Request, plus optional `RequestInit`.
1859
+ *
1860
+ * @param input - URL string, URL object, or Request.
1861
+ * @param init - Optional RequestInit (method, headers, body, etc.).
1862
+ * @returns A Web Standard Response.
1863
+ */
1864
+ request(input, init) {
1865
+ if (typeof input === "string" && !input.startsWith("http://") && !input.startsWith("https://")) input = `http://localhost${input.startsWith("/") ? "" : "/"}${input}`;
1866
+ const req = input instanceof Request ? input : new Request(input, init);
1867
+ return this.fetch(req);
1868
+ }
1700
1869
  };
1870
+ function createFakeIncomingMessage(request, pathname, forwardFrom, forwardHeaders) {
1871
+ const req = new IncomingMessage(new Socket({}));
1872
+ req.method = request.method;
1873
+ req.url = pathname;
1874
+ const headers = {};
1875
+ if (forwardFrom && forwardHeaders !== false) {
1876
+ const headerList = Array.isArray(forwardHeaders) ? forwardHeaders : DEFAULT_FORWARD_HEADERS;
1877
+ for (const h of headerList) {
1878
+ const val = forwardFrom.headers[h];
1879
+ if (typeof val === "string" && val) headers[h] = val;
1880
+ }
1881
+ }
1882
+ request.headers.forEach((value, key) => {
1883
+ headers[key] = value;
1884
+ });
1885
+ req.headers = headers;
1886
+ return req;
1887
+ }
1701
1888
  /**
1702
1889
  * Creates a new WooksHttp application instance.
1703
1890
  * @example
@@ -1808,4 +1995,4 @@ function prepareTestHttpContext(options) {
1808
1995
  }
1809
1996
 
1810
1997
  //#endregion
1811
- export { DEFAULT_LIMITS, EHttpStatusCode, HttpError, HttpResponse, WooksHttp, WooksHttpResponse, WooksURLSearchParams, createHttpApp, createHttpContext, httpKind, httpStatusCodes, prepareTestHttpContext, rawBodySlot, renderCacheControl, securityHeaders, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useLogger, useRequest, useResponse, useRouteParams, useUrlParams };
1998
+ export { DEFAULT_LIMITS, EHttpStatusCode, HttpError, HttpResponse, WooksHttp, WooksHttpResponse, WooksURLSearchParams, createHttpApp, createHttpContext, httpKind, httpStatusCodes, prepareTestHttpContext, rawBodySlot, recordToWebHeaders, renderCacheControl, securityHeaders, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useLogger, useRequest, useResponse, useRouteParams, useUrlParams };