Skip to content


Subversion checkout URL

You can clone with
Download ZIP


ResponseStream.prototype.redirect needs to call this.end() instead of this.response.end() #41

wants to merge 1 commit into from

3 participants


I am testing the latest version of union with flatiron-passport which does OAuth redirects. What happens is the session is not getting stored on redirect which causes the OAuth to fail after the redirect occurs. What cases this failure is that none of the end hooks are triggered when a redirect occurs. This can easily be fixed if we use this.end() in the ResponseStream instead of using this.response.end() since that bypasses any registered end callbacks.

I stepped through this and it still calls this.response.end() after these callbacks have been triggered which leads me to believe that this fix is good, but would love to hear your opinion on that.




I thought @indexzero fixed it with this commit edc77cd

Can you confirm again?


No, unfortunately that does not fix the issue. That is why I had to create this patch.

By calling this.response.end(); instead of this.end(), this bypasses any exit hooks that may need to be triggered and goes straight to the http layer for redirection. For my case, this was causing the Session to not be saved because the following code was being skipped

The proper fix, it seems, is to just call the ResponseStream's end method which triggers all end handlers (which triggers the one from Connect to save the session). I will see what I can do to work up a test for you guys.


Here is a quick test you can run that exposes this issue.

var flatiron    = require('flatiron');
var connect = require('connect');
var app         =;


app.router.get('/redirect', function() {
  this.req.session.storeMe = 'I should be here!';

app.router.get('/tohere', function() {
  this.res.writeHead(200, {'Content-Type': 'text/html'});
  var output = this.req.session.storeMe ? 'IT WORKS!!!' : 'FAIL!!!!';

// Add session support.

// Start the flatiron server at port 3000.
app.start(3000, function(){
  console.log('> flatiron server started on port 3000');

With this patch in place, if you navigate to http://localhost:3000/redirect, it should say "IT WORKS!!!". Without it, it says "FAIL!"


Yeah. I totally derped there. I fixed it and published it in union@0.3.6

@indexzero indexzero closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 19, 2012
  1. @travist

    Should be using this.end() instead of this.response.end() so that it …

    travist authored
    …will trigger all necessary hooks.
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/response-stream.js
8 lib/response-stream.js
@@ -162,15 +162,15 @@ ResponseStream.prototype.write = function (data) {
ResponseStream.prototype.redirect = function(path, status) {
var url = '';
if(~path.indexOf('://')) {
url = path;
} else {
url += this.req.connection.encrypted ? 'https://' : 'http://';
url +=;
- url += (path[0] === '/') ? path : '/' + path;
+ url += (path[0] === '/') ? path : '/' + path;
this.response.writeHead(status || 302, { 'Location': url });
- this.response.end();
+ this.end();
Something went wrong with that request. Please try again.