redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

cookies or headers bug #93

Closed cgarciae closed 8 years ago

cgarciae commented 9 years ago

I've been trying to do a basic test with cookies with no luck. Here is my code

@app.Route ('/cookies')
cookie ()
{
    var cookie = app.request.headers['cookie'];
    app.response = app.response.change(headers: {'set-cookie':'ID=2; Path=/; HttpOnly'});
    return cookie;
}

The browser doesn't receive the Set-Cookie header. However, it works if you return a shelf.Response with its headers set

@app.Route ('/cookies')
cookie ()
{
    var cookie = app.request.headers['cookie'];
    return new shelf.Response.ok (cookie, headers: {'set-cookie':'ID=2; Path=/; HttpOnly'});
}
cgarciae commented 9 years ago

@luizmineo Tried digging in the source code to fix the problem. My hypothesis is that the shelf.Response modified in the route is not being used because if the response of a route is NOT a shelf.Response a new shelf.Response is created using the output value from the route's function, but doesn't carry the headers set during the routes execution. Redstone is a little hard to understand since I don't know shelf. Looked for a while at server_impl but couldn't find the actual line where the route's function is executed. I'll need a basic intro to start contributing with actual code.

luizmineo commented 9 years ago

This is the expected behavior. Shelf messages (request and response) are immutable, and the change() method always creates a new instance.

v0.6 has a better library layout, which are easier to understand. I suggest that you explore this version instead of the current code base.