Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Sessions are not saved when using Connect.session() middleware. #39

Closed
wants to merge 1 commit into from

4 participants

@travist

I am working on getting FlatIron to play nicely with Passport.js with https://github.com/travist/flatiron-passport.

I noticed that the session saving fails with OAuth because https://github.com/senchalabs/connect/blob/master/lib/middleware/session.js#L274 tries to inject itself before the end method is called. However this is attached to the this pointer of the request object and not this.res.

This can all be fixed if we just check to see if the end method is attached to this, and call it instead if it is... If not, then fallback to current behavior.

@pksunkara

I will look into this soon. Thanks.

@pksunkara

@travist Can you post an example so that I can test this?

Sorry for the delay.

@indexzero
Owner

This is a bug in the original implementation of redirect. It has been fixed in HEAD

@indexzero indexzero closed this
@davidrslopes

As of Union version 0.3.5 res is renamed response like so:
this.response.end();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/response-stream.js
View
15 lib/response-stream.js
@@ -162,17 +162,24 @@ 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 += this.req.headers.host;
- url += (path[0] === '/') ? path : '/' + path;
+ url += (path[0] === '/') ? path : '/' + path;
}
-
+
this.res.writeHead(status || 302, {
'Location': url
});
- this.res.end();
+
+ // Prefer this.end over this.res.end so that connect.session will save.
+ if ((typeof this.end)==='function') {
+ this.end();
+ }
+ else {
+ this.res.end();
+ }
};
Something went wrong with that request. Please try again.