This repository has been archived by the owner. It is now read-only.

Error after 302 then 304 #7051

Closed
Hamdy opened this Issue Feb 5, 2014 · 4 comments

Comments

Projects
None yet
4 participants
@Hamdy

Hamdy commented Feb 5, 2014

Hello,
am having an http action that redirects user to another action when user has met some condition.
the problem is I get frequently get garbage HTML in my browser page like:

    </div>
    </div>
</div>
        <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
        ..........
    </body>
</html>HTTP/1.1 304 Not Modified
ETag: "-485306310"
Date: Wed, 05 Feb 2014 17:32:56 GMT
Connection: keep-alive

This case sometimes happens for me when there's 302 then 304 HTTP responses.

debug: discarding transport
Passport: DeSerialzing User from session 52f254ffa33d553431b2faf6
GET / 302 31ms - 66b
Passport: DeSerialzing User from session 52f254ffa33d553431b2faf6
GET /go 304 27ms

Then I get that garbage HTML in my browser

@indutny

This comment has been minimized.

Show comment Hide comment
@indutny

indutny Feb 5, 2014

Member

Hello! May I ask you to provide a test case for us?

Member

indutny commented Feb 5, 2014

Hello! May I ask you to provide a test case for us?

@trevnorris trevnorris added the http label Feb 5, 2014

@Hamdy

This comment has been minimized.

Show comment Hide comment
@Hamdy

Hamdy Feb 6, 2014

Hello, I don't have a test case for this,
but my use case was the following:

# home ('/')
exports.home = function(req, res){
     if(user is logged in)
            redirect('/chat')
}

 # chat ('/chat')
exports.chat = function(req, res){
     if(user not logged in)
            redirect('/')
      else
          // every thing is fine
}

Now The error used to happen more often when connection is slow a bit, and I'm logged in
and my location is "/chat" then trying to go to "/", this error happens
as / will redirect me back to /chat.

We replaced redirect('/chat') with

   res.writeHead(302, { 'Location': '/chat'});
    res.end();

This seems to help in solving the problem, as we can't reproduce it again.

Hamdy commented Feb 6, 2014

Hello, I don't have a test case for this,
but my use case was the following:

# home ('/')
exports.home = function(req, res){
     if(user is logged in)
            redirect('/chat')
}

 # chat ('/chat')
exports.chat = function(req, res){
     if(user not logged in)
            redirect('/')
      else
          // every thing is fine
}

Now The error used to happen more often when connection is slow a bit, and I'm logged in
and my location is "/chat" then trying to go to "/", this error happens
as / will redirect me back to /chat.

We replaced redirect('/chat') with

   res.writeHead(302, { 'Location': '/chat'});
    res.end();

This seems to help in solving the problem, as we can't reproduce it again.

@indutny

This comment has been minimized.

Show comment Hide comment
@indutny

indutny Feb 14, 2014

Member

Sorry, could you please provide a complete test case that won't require me to finish it in order to be able to test it?

Member

indutny commented Feb 14, 2014

Sorry, could you please provide a complete test case that won't require me to finish it in order to be able to test it?

@jasnell

This comment has been minimized.

Show comment Hide comment
@jasnell

jasnell May 28, 2015

Member

Closing. @Hamdy if this is still an issue, please provide a complete test case as @indutny asked and we can reopen if necessary.

Member

jasnell commented May 28, 2015

Closing. @Hamdy if this is still an issue, please provide a complete test case as @indutny asked and we can reopen if necessary.

@jasnell jasnell closed this May 28, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.