ultimate-express 1.2.8 → 1.2.10

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/README.md CHANGED
@@ -135,7 +135,6 @@ In general, basically all features and options are supported. Use [Express 4.x d
135
135
  - ✅ express.json()
136
136
  - ✅ express.urlencoded()
137
137
  - ✅ express.static()
138
- - - Additionally you can pass `options.ifModifiedSince` to support If-Modified-Since header (this header is not supported in normal Express, but is supported in µExpress)
139
138
  - ✅ express.text()
140
139
  - ✅ express.raw()
141
140
  - 🚧 express.request (this is not a constructor but a prototype for replacing methods)
@@ -255,7 +254,7 @@ In general, basically all features and options are supported. Use [Express 4.x d
255
254
  - - ✅ Range header
256
255
  - - ✅ Setting ETag header
257
256
  - - ✅ If-Match header
258
- - - ✅ If-Modified-Since header (with `options.ifModifiedSince` option)
257
+ - - ✅ If-Modified-Since header
259
258
  - - ✅ If-Unmodified-Since header
260
259
  - - ✅ If-Range header
261
260
  - ✅ res.sendStatus()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
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
@@ -196,15 +196,8 @@ module.exports = class Response extends Writable {
196
196
  if(data && !this.headers['etag'] && etagFn && !this.req.noEtag) {
197
197
  this.set('etag', etagFn(data));
198
198
  }
199
- if(this.req.fresh) {
200
- if(!this.headersSent) {
201
- this._res.writeStatus('304');
202
- }
203
- this.headersSent = true;
204
- this.socket.emit('close');
205
- return this._res.end();
206
- }
207
- this._res.writeStatus(this.statusCode.toString());
199
+ const fresh = this.req.fresh;
200
+ this._res.writeStatus(fresh ? '304' : this.statusCode.toString());
208
201
  for(const header in this.headers) {
209
202
  if(header === 'content-length') {
210
203
  continue;
@@ -215,6 +208,11 @@ module.exports = class Response extends Writable {
215
208
  this._res.writeHeader('content-type', 'text/html' + (typeof data === 'string' ? `; charset=utf-8` : ''));
216
209
  }
217
210
  this.headersSent = true;
211
+ if(fresh) {
212
+ this._res.end();
213
+ this.socket.emit('close');
214
+ return;
215
+ }
218
216
  }
219
217
  if(!data && this.headers['content-length']) {
220
218
  this._res.endWithoutBody(this.headers['content-length'].toString());
@@ -396,21 +394,6 @@ module.exports = class Response extends Writable {
396
394
  return done(new Error('Precondition Failed'));
397
395
  }
398
396
 
399
- // if-modified-since
400
- if(options.ifModifiedSince) {
401
- let modifiedSince = this.req.headers['if-modified-since'];
402
- let lastModified = this.headers['last-modified'];
403
- if(options.lastModified && lastModified && modifiedSince) {
404
- modifiedSince = parseHttpDate(modifiedSince);
405
- lastModified = parseHttpDate(lastModified);
406
-
407
- if(!isNaN(lastModified) && !isNaN(modifiedSince) && lastModified <= modifiedSince) {
408
- this.status(304);
409
- return this.end();
410
- };
411
- }
412
- }
413
-
414
397
  // range requests
415
398
  let offset = 0, len = stat.size, ranged = false;
416
399
  if(options.acceptRanges) {
@@ -440,6 +423,11 @@ module.exports = class Response extends Writable {
440
423
  }
441
424
  }
442
425
 
426
+ // if-modified-since, if-none-match
427
+ if(this.req.fresh) {
428
+ return this.end();
429
+ }
430
+
443
431
  if(this.req.method === 'HEAD') {
444
432
  this.set('Content-Length', stat.size);
445
433
  return this.end();
@@ -576,7 +564,6 @@ module.exports = class Response extends Writable {
576
564
  if(!options) {
577
565
  options = {};
578
566
  }
579
- // TODO: signed cookies
580
567
  let val = typeof value === 'object' ? "j:"+JSON.stringify(value) : String(value);
581
568
  if(options.maxAge != null) {
582
569
  const maxAge = options.maxAge - 0;