Skip to content
Myr

Added req.fresh and req.stale

Before adoption: this commit came in with the history the project adopted, so no landing records it.

lame usage example: app.get('/user/:id', function(req, res){ var id = req.params.id; res.set('ETag', 'user-' + id); if (req.fresh) return res.send(304); setTimeout(function(){ res.send('large expensive user response ' + id); }, 2000); });

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent de17b28 · Browse files · 1 file+27 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−0 removed

  • other:+27 added−0 removed

1 file+27 added−0 removed

modified:lib/request.js+27 added
10 unmodified lines
1112var http = require('http')13 , req = http.IncomingMessage.prototype14 , utils = require('./utils')15 , connect = require('connect')16 , parse = require('url').parse17 , mime = require('mime');1819/**
313 unmodified lines
333 }334 return !! ~contentType.indexOf(type);335};336337/**338 * Check if the request is fresh, aka339 * Last-Modified and/or the ETag340 * still match.341 *342 * @return {Boolean}343 * @api public344 */345346req.__defineGetter__('fresh', function(){347 return ! this.stale;348})349350/**351 * Check if the request is stale, aka352 * Last-Modified and/or the ETag for the353 * resource has changed.354 *355 * @return {Boolean}356 * @api public357 */358359req.__defineGetter__('stale', function(){360 return connect.utils.modified(this, this.res);361})362363// Callback for isXMLHttpRequest / xhr364365function isxhr() {366 return this.header('X-Requested-With', '').toLowerCase() === 'xmlhttprequest';
11 unmodified lines