Skip to content
Myr

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

1 file+13 added−13 removed

modified:lib/response.js+13 added-13 removed
89 unmodified lines
9091 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 line
106 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 }116117 // 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 lines
163 , body = JSON.stringify(obj, replacer, spaces)164 , callback = this.req.query.callback;165166 this.charset = this.charset || 'utf-8';167 this.header('Content-Type', 'application/json');167 this.set('Content-Type', 'application/json');168169 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 }173174 return this.send(body);
107 unmodified lines
282 */283284res.contentType =285res.type = function(type){286 return this.header('Content-Type', mime.lookup(type));286 return this.set('Content-Type', mime.lookup(type));287};288289/**290 * Set _Content-Disposition_ header to _attachment_ with optional `filename`.
4 unmodified lines
295 */296297res.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 lines
416 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};423424/**
66 unmodified lines
491492 // 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 }500501 // Respond502 this.statusCode = status;503 this.header('Location', url);503 this.set('Location', url);504 this.end(head ? null : body);505};506507/**
69 unmodified lines