@wooksjs/event-http 0.2.12 → 0.2.13

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.cjs CHANGED
@@ -708,6 +708,9 @@ class BaseHttpResponse {
708
708
  }
709
709
  return this;
710
710
  }
711
+ mergeFetchStatus(fetchStatus) {
712
+ this.status = this.status || useResponse().status() || fetchStatus;
713
+ }
711
714
  respond() {
712
715
  return __awaiter(this, void 0, void 0, function* () {
713
716
  const { rawResponse, hasResponded } = useResponse();
@@ -745,11 +748,19 @@ class BaseHttpResponse {
745
748
  }
746
749
  }
747
750
  else if (globalThis.Response && this.body instanceof Response /* Fetch Response */) {
748
- this.mergeStatus('ok');
751
+ this.mergeFetchStatus(this.body.status);
749
752
  if (method === 'HEAD') {
750
753
  res.end();
751
754
  }
752
755
  else {
756
+ const additionalHeaders = {};
757
+ if (this.body.headers.get('content-length')) {
758
+ additionalHeaders['content-length'] = this.body.headers.get('content-length');
759
+ }
760
+ if (this.body.headers.get('content-type')) {
761
+ additionalHeaders['content-type'] = this.body.headers.get('content-type');
762
+ }
763
+ res.writeHead(this.status, Object.assign(Object.assign({}, additionalHeaders), this._headers));
753
764
  yield respondWithFetch(this.body.body, res);
754
765
  }
755
766
  }
@@ -812,7 +823,7 @@ class HttpErrorRenderer extends BaseHttpResponseRenderer {
812
823
  `<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
813
824
  `<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
814
825
  `<center><h4>${data.message}</h1></center><hr color="#666">` +
815
- `<center style="color: #666;"> Wooks v${"0.2.12"} </center>` +
826
+ `<center style="color: #666;"> Wooks v${"0.2.13"} </center>` +
816
827
  `${keys.length ? `<pre style="${preStyles}">${JSON.stringify(Object.assign(Object.assign({}, data), { statusCode: undefined, message: undefined, error: undefined }), null, ' ')}</pre>` : ''}` +
817
828
  '</body></html>';
818
829
  }
package/dist/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export declare class BaseHttpResponse<BodyType = unknown> {
36
36
  getHeader(name: string): string | string[];
37
37
  protected mergeHeaders(): this;
38
38
  protected mergeStatus(renderedBody: string | Uint8Array): this;
39
+ protected mergeFetchStatus(fetchStatus: number): void;
39
40
  respond(): Promise<unknown>;
40
41
  }
41
42
 
package/dist/index.mjs CHANGED
@@ -706,6 +706,9 @@ class BaseHttpResponse {
706
706
  }
707
707
  return this;
708
708
  }
709
+ mergeFetchStatus(fetchStatus) {
710
+ this.status = this.status || useResponse().status() || fetchStatus;
711
+ }
709
712
  respond() {
710
713
  return __awaiter(this, void 0, void 0, function* () {
711
714
  const { rawResponse, hasResponded } = useResponse();
@@ -743,11 +746,19 @@ class BaseHttpResponse {
743
746
  }
744
747
  }
745
748
  else if (globalThis.Response && this.body instanceof Response /* Fetch Response */) {
746
- this.mergeStatus('ok');
749
+ this.mergeFetchStatus(this.body.status);
747
750
  if (method === 'HEAD') {
748
751
  res.end();
749
752
  }
750
753
  else {
754
+ const additionalHeaders = {};
755
+ if (this.body.headers.get('content-length')) {
756
+ additionalHeaders['content-length'] = this.body.headers.get('content-length');
757
+ }
758
+ if (this.body.headers.get('content-type')) {
759
+ additionalHeaders['content-type'] = this.body.headers.get('content-type');
760
+ }
761
+ res.writeHead(this.status, Object.assign(Object.assign({}, additionalHeaders), this._headers));
751
762
  yield respondWithFetch(this.body.body, res);
752
763
  }
753
764
  }
@@ -810,7 +821,7 @@ class HttpErrorRenderer extends BaseHttpResponseRenderer {
810
821
  `<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
811
822
  `<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
812
823
  `<center><h4>${data.message}</h1></center><hr color="#666">` +
813
- `<center style="color: #666;"> Wooks v${"0.2.12"} </center>` +
824
+ `<center style="color: #666;"> Wooks v${"0.2.13"} </center>` +
814
825
  `${keys.length ? `<pre style="${preStyles}">${JSON.stringify(Object.assign(Object.assign({}, data), { statusCode: undefined, message: undefined, error: undefined }), null, ' ')}</pre>` : ''}` +
815
826
  '</body></html>';
816
827
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-http",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "@wooksjs/event-http",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -31,9 +31,9 @@
31
31
  "url": "https://github.com/wooksjs/wooksjs/issues"
32
32
  },
33
33
  "peerDependencies": {
34
- "wooks": "0.2.12",
34
+ "wooks": "0.2.13",
35
35
  "@prostojs/router": "^0.0.16",
36
- "@wooksjs/event-core": "0.2.12"
36
+ "@wooksjs/event-core": "0.2.13"
37
37
  },
38
38
  "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/event-http#readme"
39
39
  }