ultimate-express 1.2.8 → 1.2.9

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.9",
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,21 +196,23 @@ 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();
199
+ const fresh = this.req.fresh;
200
+ if(fresh) {
201
+ this._res.writeStatus('304');
202
+ } else {
203
+ this._res.writeStatus(this.statusCode.toString());
206
204
  }
207
- this._res.writeStatus(this.statusCode.toString());
208
205
  for(const header in this.headers) {
209
206
  if(header === 'content-length') {
210
207
  continue;
211
208
  }
212
209
  this._res.writeHeader(header, this.headers[header]);
213
210
  }
211
+ if(fresh) {
212
+ this.headersSent = true;
213
+ this.socket.emit('close');
214
+ return this._res.end();
215
+ }
214
216
  if(!this.headers['content-type']) {
215
217
  this._res.writeHeader('content-type', 'text/html' + (typeof data === 'string' ? `; charset=utf-8` : ''));
216
218
  }
@@ -396,21 +398,6 @@ module.exports = class Response extends Writable {
396
398
  return done(new Error('Precondition Failed'));
397
399
  }
398
400
 
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
401
  // range requests
415
402
  let offset = 0, len = stat.size, ranged = false;
416
403
  if(options.acceptRanges) {
@@ -440,6 +427,11 @@ module.exports = class Response extends Writable {
440
427
  }
441
428
  }
442
429
 
430
+ // if-modified-since, if-none-match
431
+ if(this.req.fresh) {
432
+ return this.end();
433
+ }
434
+
443
435
  if(this.req.method === 'HEAD') {
444
436
  this.set('Content-Length', stat.size);
445
437
  return this.end();
@@ -576,7 +568,6 @@ module.exports = class Response extends Writable {
576
568
  if(!options) {
577
569
  options = {};
578
570
  }
579
- // TODO: signed cookies
580
571
  let val = typeof value === 'object' ? "j:"+JSON.stringify(value) : String(value);
581
572
  if(options.maxAge != null) {
582
573
  const maxAge = options.maxAge - 0;