Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

etag check middleware missing #224

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

etag check middleware missing #224

fengmk2 opened this issue Feb 27, 2014 · 6 comments
Assignees
Labels
Milestone

Comments

@fengmk2
Copy link
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
@dead-horse
Copy link
Member

use https://github.com/koajs/etag ?

@fengmk2
Copy link
Member Author

fengmk2 commented Feb 27, 2014

嗯,用它吧

@fengmk2
Copy link
Member Author

fengmk2 commented Feb 27, 2014

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

@fengmk2
Copy link
Member Author

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
Copy link
Member Author

fengmk2 commented Feb 27, 2014

我实现一个 koa-fresh

@fengmk2
Copy link
Member Author

fengmk2 commented Feb 27, 2014

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

dead-horse added a commit that referenced this issue Feb 27, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants