Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize CookieJar requests internally, document normalizeRequest #109

Open
crocket opened this issue Jul 9, 2014 · 5 comments
Open

Normalize CookieJar requests internally, document normalizeRequest #109

crocket opened this issue Jul 9, 2014 · 5 comments
Labels

Comments

@crocket
Copy link

crocket commented Jul 9, 2014

request supports it, but there is no documentation about cookies in q-io.

@Stuk
Copy link
Collaborator

Stuk commented Jul 14, 2014

Yep, this isn't documented, sorry. You can use the http-apps Chain to create a request function that stores cookies:

var HTTP = require("q-io/http");
var HttpApps = require("q-io/http-apps");

var cookieRequest = HttpApps.Chain()
    .use(function (app) { return function (request) { return app(HTTP.normalizeRequest(request)); }; })
    .use(HttpApps.CookieJar)
    // you can add other middleware here too
    .end(HTTP.request);

cookieRequest("http://www.google.com")
.done(function (response) {
    console.log(response);
});

@Stuk Stuk changed the title Does q-ui support logging in a web application with a login cookie? Does q-io support logging in a web application with a login cookie? Jul 14, 2014
@crocket
Copy link
Author

crocket commented Jul 14, 2014

This is more complicated than I thought. Can you make API simpler?

@Stuk
Copy link
Collaborator

Stuk commented Jul 14, 2014

The need for normalizeRequest here is an oversight and shouldn't be needed, otherwise the API is designed to be very composable, which unfortunately does lead to some complexity.

If you don't think you will need the chain then you can just do:

var cookieRequest = HttpApps.CookieJar(HTTP.request);
cookieRequest(HTTP.normalizeRequest("http://www.google.com")).then( ... );

@kriskowal
Copy link
Owner

Let’s treat the need for normalizeRequest as a bug with two sides.

  1. Need to document HttpApps.Normalize.
  2. HttpApps.CookieJar should normalize internally.
var HTTP = require("q-io/http");
var HttpApps = require("q-io/http-apps");

var cookieRequest = HttpApps.Chain()
    .use(HttpApps.Normalize)
    .use(HttpApps.CookieJar)
    .end(HTTP.request);

cookieRequest("http://www.google.com")
.done(function (response) {
    console.log(response);
});

On Mon, Jul 14, 2014 at 3:49 PM, Stuart Knightley [email protected]
wrote:

The need for normalizeRequest here is an oversight and shouldn't be
needed, otherwise the API is designed to be very composable, which
unfortunately does lead to some complexity.

If you don't think you will need the chain then you can just do:

var cookieRequest = HttpApps.CookieJar(HTTP.request);cookieRequest(HTTP.normalizeRequest("http://www.google.com")).then( ... );


Reply to this email directly or view it on GitHub
#109 (comment).

@Stuk
Copy link
Collaborator

Stuk commented Jul 14, 2014

👍

@kriskowal kriskowal changed the title Does q-io support logging in a web application with a login cookie? Normalize CookieJar requests internally, document normalizeRequest Feb 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants