Skip to content

Commit

Permalink
refactor: use ctx.setRawHeader (eggjs#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored and fengmk2 committed Aug 29, 2016
1 parent 2adf02d commit 4f3029d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/extend/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const proto = module.exports = {
if (!jsonpFunction) {
this.body = obj;
} else {
this.set('X-Content-Type-Options', 'nosniff');
this.setRawHeader('X-Content-Type-Options', 'nosniff');
this.type = 'js';
this.body = jsonpBody(obj, jsonpFunction, options);
}
Expand Down
4 changes: 2 additions & 2 deletions app/middleware/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ module.exports = (_, app) => {
const poweredBy = typeof app.poweredBy === 'string' ? app.poweredBy : null;

return function* meta(next) {
if (poweredBy) this.set('X-Powered-By', poweredBy);
if (poweredBy) this.setRawHeader('X-Powered-By', poweredBy);

yield next;

// total response time header
this.set('X-Readtime', Date.now() - this.starttime);
this.setRawHeader('X-Readtime', Date.now() - this.starttime);
};
};
7 changes: 3 additions & 4 deletions app/middleware/site_file.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

// favicon.ico crossdomain.xml robots.txt support

const path = require('path');
const MAX_AGE = 30 * 24 * 68 * 60;

const MAX_AGE_VALUE = 'public, max-age=2592000'; // 30 days

module.exports = options => {
return function* siteFile(next) {
Expand All @@ -20,7 +19,7 @@ module.exports = options => {
// '/robots.txt': Buffer <xx..
// content is buffer
if (Buffer.isBuffer(content)) {
this.set('Cache-Control', `public, max-age=${MAX_AGE}`);
this.setRawHeader('Cache-Control', MAX_AGE_VALUE);
this.body = content;
this.type = path.extname(this.path);
return;
Expand Down

0 comments on commit 4f3029d

Please sign in to comment.