Skip to content

Commit 99820e7

Browse files
committed
Refactored req/res proto assignments
since the names may change in the near future (is suspect at least) due to inconsistancies
1 parent 6a03a92 commit 99820e7

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/request.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
var http = require('http')
1313
, utils = require('./utils')
14-
, mime = require('connect').utils.mime;
14+
, mime = require('connect').utils.mime
15+
, req = http.IncomingMessage.prototype;
1516

1617
/**
1718
* Default flash formatters.
@@ -48,7 +49,7 @@ var flashFormatters = exports.flashFormatters = {
4849
* @api public
4950
*/
5051

51-
http.IncomingMessage.prototype.header = function(name, defaultValue){
52+
req.header = function(name, defaultValue){
5253
return this.headers[name.toLowerCase()] || defaultValue;
5354
};
5455

@@ -82,7 +83,7 @@ http.IncomingMessage.prototype.header = function(name, defaultValue){
8283
* @api public
8384
*/
8485

85-
http.IncomingMessage.prototype.accepts = function(type){
86+
req.accepts = function(type){
8687
var accept = this.header('Accept');
8788

8889
// Normalize extensions ".json" -> "json"
@@ -125,7 +126,7 @@ http.IncomingMessage.prototype.accepts = function(type){
125126
* @api public
126127
*/
127128

128-
http.IncomingMessage.prototype.param = function(name, defaultValue){
129+
req.param = function(name, defaultValue){
129130
// Route params like /user/:id
130131
if (this.params[name] !== undefined) {
131132
return this.params[name];
@@ -176,7 +177,7 @@ http.IncomingMessage.prototype.param = function(name, defaultValue){
176177
* @api public
177178
*/
178179

179-
http.IncomingMessage.prototype.flash = function(type, msg){
180+
req.flash = function(type, msg){
180181
var msgs = this.session.flash = this.session.flash || {};
181182
if (type && msg) {
182183
var i = 2
@@ -243,7 +244,7 @@ http.IncomingMessage.prototype.flash = function(type, msg){
243244
* @api public
244245
*/
245246

246-
http.IncomingMessage.prototype.is = function(type){
247+
req.is = function(type){
247248
var fn = this.app.is(type);
248249
if (fn) return fn(this);
249250
var contentType = this.headers['content-type'];
@@ -273,5 +274,5 @@ function isxhr() {
273274
* @api public
274275
*/
275276

276-
http.IncomingMessage.prototype.__defineGetter__('isXMLHttpRequest', isxhr);
277-
http.IncomingMessage.prototype.__defineGetter__('xhr', isxhr);
277+
req.__defineGetter__('isXMLHttpRequest', isxhr);
278+
req.__defineGetter__('xhr', isxhr);

lib/response.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ var fs = require('fs')
1515
, pump = require('sys').pump
1616
, utils = require('connect').utils
1717
, parseRange = require('./utils').parseRange
18-
, mime = utils.mime;
18+
, mime = utils.mime
19+
, res = http.ServerResponse.prototype;
1920

2021
/**
2122
* Header fields supporting multiple values.
@@ -45,7 +46,7 @@ var multiple = ['Set-Cookie'];
4546
* @api public
4647
*/
4748

48-
http.ServerResponse.prototype.send = function(body, headers, status){
49+
res.send = function(body, headers, status){
4950
// Allow status as second arg
5051
if (typeof headers === 'number') {
5152
status = headers,
@@ -129,7 +130,7 @@ http.ServerResponse.prototype.send = function(body, headers, status){
129130
* @api public
130131
*/
131132

132-
http.ServerResponse.prototype.sendfile = function(path, fn){
133+
res.sendfile = function(path, fn){
133134
var self = this
134135
, ranges = self.req.headers.range
135136
, head = 'HEAD' == self.req.method;
@@ -202,7 +203,7 @@ http.ServerResponse.prototype.sendfile = function(path, fn){
202203
* @api public
203204
*/
204205

205-
http.ServerResponse.prototype.contentType = function(type){
206+
res.contentType = function(type){
206207
if (!~type.indexOf('.')) type = '.' + type;
207208
return this.header('Content-Type', mime.type(type));
208209
};
@@ -215,7 +216,7 @@ http.ServerResponse.prototype.contentType = function(type){
215216
* @api public
216217
*/
217218

218-
http.ServerResponse.prototype.attachment = function(filename){
219+
res.attachment = function(filename){
219220
this.header('Content-Disposition', filename
220221
? 'attachment; filename="' + path.basename(filename) + '"'
221222
: 'attachment');
@@ -234,7 +235,7 @@ http.ServerResponse.prototype.attachment = function(filename){
234235
* @api public
235236
*/
236237

237-
http.ServerResponse.prototype.download = function(path, filename, fn){
238+
res.download = function(path, filename, fn){
238239
this.attachment(filename || path).sendfile(path, fn);
239240
};
240241

@@ -253,7 +254,7 @@ http.ServerResponse.prototype.download = function(path, filename, fn){
253254
* @api public
254255
*/
255256

256-
http.ServerResponse.prototype.header = function(name, val){
257+
res.header = function(name, val){
257258
if (val === undefined) {
258259
return this.headers[name];
259260
} else {
@@ -270,7 +271,7 @@ http.ServerResponse.prototype.header = function(name, val){
270271
* @api public
271272
*/
272273

273-
http.ServerResponse.prototype.clearCookie = function(name){
274+
res.clearCookie = function(name){
274275
this.cookie(name, '', { expires: new Date(1) });
275276
};
276277

@@ -288,7 +289,7 @@ http.ServerResponse.prototype.clearCookie = function(name){
288289
* @api public
289290
*/
290291

291-
http.ServerResponse.prototype.cookie = function(name, val, options){
292+
res.cookie = function(name, val, options){
292293
var cookie = utils.serializeCookie(name, val, options);
293294
this.header('Set-Cookie', cookie);
294295
};
@@ -334,7 +335,7 @@ http.ServerResponse.prototype.cookie = function(name, val, options){
334335
* @api public
335336
*/
336337

337-
http.ServerResponse.prototype.redirect = function(url, status){
338+
res.redirect = function(url, status){
338339
var basePath = this.app.set('home') || '/'
339340
, status = status || 302
340341
, body;
@@ -379,7 +380,7 @@ http.ServerResponse.prototype.redirect = function(url, status){
379380
* @api public
380381
*/
381382

382-
http.ServerResponse.prototype.local = function(name, val){
383+
res.local = function(name, val){
383384
this.locals = this.locals || {};
384385
return undefined === val
385386
? this.locals[name]

0 commit comments

Comments
 (0)