utilize `res.set()` internally
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent fe27989 · Browse files · 1 file·+13 added−13 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+13 added−13 removed
- other:+13 added−13 removed
Provenance
- Commit
c44f018- Tree
a406418- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
fe27989
1 file changed+13 added−13 removed
modified:lib/response.js+13 added-13 removed
89 unmodified lines90 91 switch (typeof body) {92 // response status93 case 'number':94- this.header('Content-Type') || this.contentType('.txt');94+ this.get('Content-Type') || this.contentType('.txt');95 this.statusCode = body;96 body = http.STATUS_CODES[body];97 break;98 // string defaulting to html99 case 'string':100- if (!this.header('Content-Type')) {100+ if (!this.get('Content-Type')) {101 this.charset = this.charset || 'utf-8';102 this.contentType('.html');103 }104 break;1 unmodified line106 case 'object':107 if (null == body) {108 body = '';109 } else if (Buffer.isBuffer(body)) {110- this.header('Content-Type') || this.contentType('.bin');110+ this.get('Content-Type') || this.contentType('.bin');111 } else {112 return this.json(body);113 }114 break;115 }116 117 // populate Content-Length118- if (undefined !== body && !this.header('Content-Length')) {119- this.header('Content-Length', Buffer.isBuffer(body)118+ if (undefined !== body && !this.get('Content-Length')) {119+ this.set('Content-Length', Buffer.isBuffer(body)120 ? body.length121 : Buffer.byteLength(body));122 }123 39 unmodified lines163 , body = JSON.stringify(obj, replacer, spaces)164 , callback = this.req.query.callback;165 166 this.charset = this.charset || 'utf-8';167- this.header('Content-Type', 'application/json');167+ this.set('Content-Type', 'application/json');168 169 if (callback && jsonp) {170- this.header('Content-Type', 'text/javascript');170+ this.set('Content-Type', 'text/javascript');171 body = callback.replace(/[^\w$.]/g, '') + '(' + body + ');';172 }173 174 return this.send(body);107 unmodified lines282 */283 284 res.contentType =285 res.type = function(type){286- return this.header('Content-Type', mime.lookup(type));286+ return this.set('Content-Type', mime.lookup(type));287 };288 289 /**290 * Set _Content-Disposition_ header to _attachment_ with optional `filename`.4 unmodified lines295 */296 297 res.attachment = function(filename){298 if (filename) this.type(filename);299- this.header('Content-Disposition', filename299+ this.set('Content-Disposition', filename300 ? 'attachment; filename="' + basename(filename) + '"'301 : 'attachment');302 return this;303 };112 unmodified lines416 if ('object' == typeof val) val = 'j:' + JSON.stringify(val);417 if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);418 if (null == options.path) options.path = '/';419 var cookie = utils.serializeCookie(name, val, options);420- this.header('Set-Cookie', cookie);420+ this.set('Set-Cookie', cookie);421 return this;422 };423 424 /**66 unmodified lines491 492 // Support text/{plain,html} by default493 if (req.accepts('html')) {494 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';495- this.header('Content-Type', 'text/html');495+ this.set('Content-Type', 'text/html');496 } else {497 body = statusCodes[status] + '. Redirecting to ' + url;498- this.header('Content-Type', 'text/plain');498+ this.set('Content-Type', 'text/plain');499 }500 501 // Respond502 this.statusCode = status;503- this.header('Location', url);503+ this.set('Location', url);504 this.end(head ? null : body);505 };506 507 /**69 unmodified lines