bareserver 0.1.0 → 0.1.1

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/index.js +21 -4
  2. package/package.json +5 -5
package/index.js CHANGED
@@ -306,19 +306,36 @@ class BareResponse {
306
306
  return this.set(field, [prev, val]);
307
307
  }
308
308
 
309
+ _getHeadersArray() {
310
+ if (!this.extraHeaders) return null;
311
+ const arr = [];
312
+ for (const k in this.extraHeaders) {
313
+ const v = this.extraHeaders[k];
314
+ if (Array.isArray(v)) {
315
+ for (let i = 0; i < v.length; i++) {
316
+ arr.push(k, v[i]);
317
+ }
318
+ } else {
319
+ arr.push(k, v);
320
+ }
321
+ }
322
+ return arr;
323
+ }
324
+
309
325
  send(body) {
310
326
  if (this.responded) return;
311
327
  this.responded = true;
328
+ const headers = this._getHeadersArray();
312
329
 
313
330
  if (Buffer.isBuffer(body)) {
314
331
  this.contentType = this.contentType || 'application/octet-stream';
315
- this._server.native.respond(this._raw.reqId, this.statusCode, this.contentType, body, this.extraHeaders);
332
+ this._server.native.respond(this._raw.reqId, this.statusCode, this.contentType, body, headers);
316
333
  } else if (typeof body === 'object' && body !== null) {
317
334
  this.contentType = this.contentType || 'application/json';
318
- this._server.native.respond(this._raw.reqId, this.statusCode, this.contentType, JSON.stringify(body), this.extraHeaders);
335
+ this._server.native.respond(this._raw.reqId, this.statusCode, this.contentType, JSON.stringify(body), headers);
319
336
  } else {
320
337
  this.contentType = this.contentType || 'text/plain; charset=utf-8';
321
- this._server.native.respond(this._raw.reqId, this.statusCode, this.contentType, String(body ?? ''), this.extraHeaders);
338
+ this._server.native.respond(this._raw.reqId, this.statusCode, this.contentType, String(body ?? ''), headers);
322
339
  }
323
340
  }
324
341
 
@@ -326,7 +343,7 @@ class BareResponse {
326
343
  if (this.responded) return;
327
344
  this.responded = true;
328
345
  this.contentType = 'application/json';
329
- this._server.native.respond(this._raw.reqId, this.statusCode, this.contentType, JSON.stringify(body), this.extraHeaders);
346
+ this._server.native.respond(this._raw.reqId, this.statusCode, this.contentType, JSON.stringify(body), this._getHeadersArray());
330
347
  }
331
348
 
332
349
  end(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bareserver",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Zero-dependency, native-fast HTTP server for Node.js",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -11,10 +11,10 @@
11
11
  "LICENSE"
12
12
  ],
13
13
  "optionalDependencies": {
14
- "bareserver-darwin-arm64": "0.1.0",
15
- "bareserver-darwin-x64": "0.1.0",
16
- "bareserver-linux-x64-gnu": "0.1.0",
17
- "bareserver-win32-x64-msvc": "0.1.0"
14
+ "bareserver-darwin-arm64": "0.1.1",
15
+ "bareserver-darwin-x64": "0.1.1",
16
+ "bareserver-linux-x64-gnu": "0.1.1",
17
+ "bareserver-win32-x64-msvc": "0.1.1"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "cargo build --release && (cp target/release/libbareserver.dylib index.node 2>/dev/null || cp target/release/libbareserver.so index.node 2>/dev/null || true)",