ultimate-express 1.2.10 → 1.2.11

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/package.json +1 -1
  2. package/src/response.js +17 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "description": "The Ultimate Express. Fastest http server with full Express compatibility, based on uWebSockets.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/response.js CHANGED
@@ -361,15 +361,15 @@ module.exports = class Response extends Writable {
361
361
  }
362
362
 
363
363
  // headers
364
- if(!this.get('Content-Type')) {
364
+ if(!this.headers['content-type']) {
365
365
  const m = mime.lookup(fullpath);
366
366
  if(m) this.type(m);
367
367
  }
368
368
  if(options.cacheControl) {
369
- this.set('Cache-Control', `public, max-age=${options.maxAge / 1000}` + (options.immutable ? ', immutable' : ''));
369
+ this.headers['cache-control'] = `public, max-age=${options.maxAge / 1000}` + (options.immutable ? ', immutable' : '');
370
370
  }
371
371
  if(options.lastModified) {
372
- this.set('Last-Modified', stat.mtime.toUTCString());
372
+ this.headers['last-modified'] = stat.mtime.toUTCString();
373
373
  }
374
374
  if(options.headers) {
375
375
  for(const header in options.headers) {
@@ -382,7 +382,7 @@ module.exports = class Response extends Writable {
382
382
 
383
383
  // etag
384
384
  if(options.etag && !this.headers['etag'] && etagFn) {
385
- this.set('etag', etagFn(stat));
385
+ this.headers['etag'] = etagFn(stat);
386
386
  }
387
387
  if(!options.etag) {
388
388
  this.req.noEtag = true;
@@ -397,7 +397,7 @@ module.exports = class Response extends Writable {
397
397
  // range requests
398
398
  let offset = 0, len = stat.size, ranged = false;
399
399
  if(options.acceptRanges) {
400
- this.set('accept-ranges', 'bytes');
400
+ this.headers['accept-ranges'] = 'bytes';
401
401
  if(this.req.headers.range) {
402
402
  let ranges = this.req.range(stat.size, {
403
403
  combine: true
@@ -410,12 +410,12 @@ module.exports = class Response extends Writable {
410
410
 
411
411
  if(ranges === -1) {
412
412
  this.status(416);
413
- this.set('Content-Range', `bytes */${stat.size}`);
413
+ this.headers['content-range'] = `bytes */${stat.size}`;
414
414
  return done(new Error('Range Not Satisfiable'));
415
415
  }
416
416
  if(ranges !== -2 && ranges.length === 1) {
417
417
  this.status(206);
418
- this.set('Content-Range', `bytes ${ranges[0].start}-${ranges[0].end}/${stat.size}`);
418
+ this.headers['content-range'] = `bytes ${ranges[0].start}-${ranges[0].end}/${stat.size}`;
419
419
  offset = ranges[0].start;
420
420
  len = ranges[0].end - ranges[0].start + 1;
421
421
  ranged = true;
@@ -501,7 +501,7 @@ module.exports = class Response extends Writable {
501
501
  if(field === 'set-cookie' && Array.isArray(value)) {
502
502
  value = value.join('; ');
503
503
  } else if(field === 'content-type') {
504
- if(value.startsWith('text/') || value === 'application/json' || value === 'application/javascript') {
504
+ if(!value.includes('charset=') && (value.startsWith('text/') || value === 'application/json' || value === 'application/javascript')) {
505
505
  value += '; charset=utf-8';
506
506
  }
507
507
  }
@@ -589,7 +589,7 @@ module.exports = class Response extends Writable {
589
589
  return this.cookie(name, '', opts);
590
590
  }
591
591
  attachment(filename) {
592
- this.set('Content-Disposition', `attachment; filename="${filename}"`);
592
+ this.headers['Content-Disposition'] = `attachment; filename="${filename}"`;
593
593
  this.type(filename.split('.').pop());
594
594
  return this;
595
595
  }
@@ -611,8 +611,8 @@ module.exports = class Response extends Writable {
611
611
  return this;
612
612
  }
613
613
  json(body) {
614
- if(!this.get('Content-Type')) {
615
- this.set('Content-Type', 'application/json; charset=utf-8');
614
+ if(!this.headers['content-type']) {
615
+ this.headers['content-type'] = 'application/json; charset=utf-8';
616
616
  }
617
617
  const escape = this.app.get('json escape');
618
618
  const replacer = this.app.get('json replacer');
@@ -623,9 +623,9 @@ module.exports = class Response extends Writable {
623
623
  let callback = this.req.query[this.app.get('jsonp callback name')];
624
624
  let body = stringify(object, this.app.get('json replacer'), this.app.get('json spaces'), this.app.get('json escape'));
625
625
 
626
- if(!this.get('Content-Type')) {
627
- this.set('Content-Type', 'application/javascript; charset=utf-8');
628
- this.set('X-Content-Type-Options', 'nosniff');
626
+ if(!this.headers['content-type']) {
627
+ this.headers['content-type'] = 'application/javascript; charset=utf-8';
628
+ this.headers['X-Content-Type-Options'] = 'nosniff';
629
629
  }
630
630
 
631
631
  if(Array.isArray(callback)) {
@@ -633,8 +633,6 @@ module.exports = class Response extends Writable {
633
633
  }
634
634
 
635
635
  if(typeof callback === 'string' && callback.length !== 0) {
636
- this.set('Content-Type', 'application/javascript; charset=utf-8');
637
- this.set('X-Content-Type-Options', 'nosniff');
638
636
  callback = callback.replace(/[^\[\]\w$.]/g, '');
639
637
 
640
638
  if(body === undefined) {
@@ -660,7 +658,7 @@ module.exports = class Response extends Writable {
660
658
  if(!path) path = this.req.get('Referer');
661
659
  if(!path) path = '/';
662
660
  }
663
- return this.set('Location', encodeUrl(path));
661
+ return this.headers['location'] = encodeUrl(path);
664
662
  }
665
663
  redirect(status, url) {
666
664
  if(typeof status !== 'number' && !url) {
@@ -669,7 +667,7 @@ module.exports = class Response extends Writable {
669
667
  }
670
668
  this.location(url);
671
669
  this.status(status);
672
- this.set('Content-Type', 'text/plain; charset=utf-8');
670
+ this.headers['content-type'] = 'text/plain; charset=utf-8';
673
671
  return this.send(`${statuses.message[status] ?? status}. Redirecting to ${url}`);
674
672
  }
675
673
 
@@ -680,7 +678,7 @@ module.exports = class Response extends Writable {
680
678
  if(ct.startsWith('text/') || ct === 'application/json' || ct === 'application/javascript') {
681
679
  ct += '; charset=UTF-8';
682
680
  }
683
- return this.set('Content-Type', ct);
681
+ return this.set('content-type', ct);
684
682
  }
685
683
  contentType(type) {
686
684
  return this.type(type);