Open crocket opened 10 years ago
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);
});
This is more complicated than I thought. Can you make API simpler?
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( ... );
Let’s treat the need for normalizeRequest as a bug with two sides.
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 notifications@github.com 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 https://github.com/kriskowal/q-io/issues/109#issuecomment-48970254.
:+1:
request supports it, but there is no documentation about cookies in q-io.