Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
bug
Milestone

Comments

@fengmk2
Copy link
Member

@fengmk2 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

@dead-horse dead-horse commented Feb 27, 2014

@fengmk2
Copy link
Member Author

@fengmk2 fengmk2 commented Feb 27, 2014

嗯,用它吧

@fengmk2
Copy link
Member Author

@fengmk2 fengmk2 commented Feb 27, 2014

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

@fengmk2
Copy link
Member Author

@fengmk2 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 fengmk2 commented Feb 27, 2014

我实现一个 koa-fresh

@fengmk2
Copy link
Member Author

@fengmk2 fengmk2 commented Feb 27, 2014

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

@fengmk2 fengmk2 closed this in 1559c16 Feb 27, 2014
dead-horse added a commit that referenced this issue Feb 27, 2014
add etag fixed #224
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants