Skip to content
Myr

Fixed res.redirect() 406. Closes #1154

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 82a9817 · Browse files · 2 files+29 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−1 removed

  • tests:+23 added−0 removed
  • other:+6 added−1 removed

2 files+29 added−1 removed

modified:lib/response.js+6 added-1 removed
344 unmodified lines
345 * @return {ServerResponse} for chaining346 * @api public347 */348349res.format = function(obj){349res.format = function(obj, fn){350 var keys = Object.keys(obj)351 , req = this.req352 , next = req.next353 , key = req.accepts(keys);
2 unmodified lines
356357 if (key) {358 this.set('Content-Type', normalizeType(key));359 obj[key](req, this, next);360 } else if (fn) {361 fn();362 } else {363 var err = new Error('Not Acceptable');364 err.status = 406;365 err.types = normalizeTypes(keys);
190 unmodified lines
556557 html: function(){558 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';559 }560 }, function(){561 body = '';562 })563564 // Respond565 this.statusCode = status;566 this.set('Location', url);567 this.set('Content-Length', Buffer.byteLength(body));568 this.end(head ? null : body);569};570571/**
69 unmodified lines
modified:test/res.redirect.js+23 added
246 unmodified lines
247 .get('/')248 .set('Accept', 'text/plain, */*')249 .end(function(res){250 res.headers.should.have.property('location', 'http://google.com');251 res.headers.should.have.property('content-length', '51');252 res.body.should.equal('Moved Temporarily. Redirecting to http://google.com');253 done();254 })255 })256 })257258 describe('when accepting neither text or html', function(){259 it('should respond with an empty body', function(done){260 var app = express();261262 app.use(function(req, res){263 res.redirect('http://google.com');264 });265266 request(app)267 .get('/')268 .set('Accept', 'foo/bar')269 .end(function(res){270 res.should.have.status(302);271 res.headers.should.have.property('location', 'http://google.com');272 res.headers.should.not.have.property('content-type');273 res.headers.should.have.property('content-length', '0');274 res.body.should.equal('');275 done();276 })277 })278 })279})