etag check middleware missing #224

Closed
fengmk2 opened this Issue Feb 27, 2014 · 6 comments

Projects

None yet

2 participants

@fengmk2
Member
fengmk2 commented Feb 27, 2014
$ cnpm install cnpm
npm WARN package.json bower@0.6.8 No repository field.
npm WARN package.json itodo@0.0.4 No repository field.
npm WARN package.json sfile@0.0.6 No repository field.
npm WARN package.json jshint@0.7.1 No repository field.
npm http GET http://r.cnpmjs.org/cnpm
npm http 200 http://r.cnpmjs.org/cnpm
npm http GET http://r.cnpmjs.org/commander/2.1.0
npm http GET http://r.cnpmjs.org/npm-request/0.0.3
npm http GET http://r.cnpmjs.org/debug/0.7.4
npm http GET http://r.cnpmjs.org/bagpipe/0.3.5
npm http GET http://r.cnpmjs.org/open/0.0.4
npm http GET http://r.cnpmjs.org/urllib/0.5.5
npm http GET http://r.cnpmjs.org/colors/0.6.2
npm http 200 http://r.cnpmjs.org/commander/2.1.0
npm http 200 http://r.cnpmjs.org/npm-request/0.0.3
npm http 200 http://r.cnpmjs.org/open/0.0.4
npm http 200 http://r.cnpmjs.org/debug/0.7.4
npm http 200 http://r.cnpmjs.org/bagpipe/0.3.5
npm http GET http://r.cnpmjs.org/debug/download/debug-0.7.4.tgz
npm http GET http://r.cnpmjs.org/npm-request/download/npm-request-0.0.3.tgz
npm http GET http://r.cnpmjs.org/bagpipe/download/bagpipe-0.3.5.tgz
npm http GET http://r.cnpmjs.org/commander/download/commander-2.1.0.tgz
npm http GET http://r.cnpmjs.org/open/download/open-0.0.4.tgz
npm http 200 http://r.cnpmjs.org/colors/0.6.2
npm http 200 http://r.cnpmjs.org/urllib/0.5.5
npm http GET http://r.cnpmjs.org/colors/download/colors-0.6.2.tgz
npm http GET http://r.cnpmjs.org/urllib/download/urllib-0.5.5.tgz
npm http 200 http://r.cnpmjs.org/debug/download/debug-0.7.4.tgz
npm http 200 http://r.cnpmjs.org/open/download/open-0.0.4.tgz
npm http 200 http://r.cnpmjs.org/npm-request/download/npm-request-0.0.3.tgz
npm http 200 http://r.cnpmjs.org/bagpipe/download/bagpipe-0.3.5.tgz
npm http 200 http://r.cnpmjs.org/colors/download/colors-0.6.2.tgz
npm http 200 http://r.cnpmjs.org/urllib/download/urllib-0.5.5.tgz
npm http 200 http://r.cnpmjs.org/commander/download/commander-2.1.0.tgz
npm http GET http://r.cnpmjs.org/buffer-concat/0.0.1
npm http GET http://r.cnpmjs.org/debug/0.7.2
npm http 200 http://r.cnpmjs.org/buffer-concat/0.0.1
npm http 200 http://r.cnpmjs.org/debug/0.7.2
npm http GET http://r.cnpmjs.org/debug/download/debug-0.7.2.tgz
npm http GET http://r.cnpmjs.org/buffer-concat/download/buffer-concat-0.0.1.tgz
npm http 200 http://r.cnpmjs.org/debug/download/debug-0.7.2.tgz
npm http 200 http://r.cnpmjs.org/buffer-concat/download/buffer-concat-0.0.1.tgz
cnpm@0.0.27 node_modules/cnpm
├── npm-request@0.0.3
├── debug@0.7.4
├── commander@2.1.0
├── colors@0.6.2
├── open@0.0.4
├── bagpipe@0.3.5
└── urllib@0.5.5 (buffer-concat@0.0.1, debug@0.7.2)
@fengmk2 fengmk2 added this to the v0.3 koa milestone Feb 27, 2014
@fengmk2 fengmk2 added the bug label Feb 27, 2014
@fengmk2 fengmk2 self-assigned this Feb 27, 2014
@fengmk2
Member
fengmk2 commented Feb 27, 2014

嗯,用它吧

@fengmk2
Member
fengmk2 commented Feb 27, 2014

我找到connect的版本了,是我们的response-patch,然后里面依赖了 response-send

@fengmk2
Member
fengmk2 commented Feb 27, 2014
// ETag support
  // TODO: W/ support
  if (len > 1024) {
    var etag = String(Buffer.isBuffer(body)
      ? crc.buffer.crc32(body)
      : crc.crc32(body));
    if (!this.getHeader('ETag')) this.setHeader('ETag', etag);
  }

  // determine if it's cacheable
  var cache = 'GET' == method || 'HEAD' == method;
  if (cache) cache = (this.statusCode >= 200 && this.statusCode < 300) || 304 == this.statusCode;

  // freshness
  if (fresh(req.headers, this._headers) && cache) {
    this.statusCode = 304;
  }

  // strip irrelevant headers
  if (204 == this.statusCode || 304 == this.statusCode) {
    this.removeHeader('Content-Type');
    this.removeHeader('Content-Length');
    body = '';
  }

  // respond
  this.end('HEAD' == method ? null : body);
  return this;
@fengmk2
Member
fengmk2 commented Feb 27, 2014

我实现一个 koa-fresh

@fengmk2
Member
fengmk2 commented Feb 27, 2014

app.use(etag());
app.use(refresh());

@fengmk2 fengmk2 referenced this issue in cnpm/koa-middlewares Feb 27, 2014
Merged

Koa fresh #1

@fengmk2 fengmk2 added a commit that closed this issue Feb 27, 2014
@fengmk2 fengmk2 add etag fixed #224 1559c16
@fengmk2 fengmk2 closed this in 1559c16 Feb 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment