Summary ask: can you expose the parser API somehow so it's possible to parse a response and update a response.body to stop errors caused by status codes?
Background: I am testing an authentication framework that returns the login page in the content body of the response which has status 401.
This is perfectly legal and acceptable thing to do, as you know, most responses with a body will have that displayed rather than the browser default if they're present.
zombie doesn't do that though, I just get an error.
That seems like a good default given zombie's domain. But it would be nice to be able to use a pipeline to make the behaviour the same as a browser.
I looked at pipeline and this is possible:
let browser = new Browser();
browser.pipeline.addHandler(async function(browser, request, response) {
// Log the response body
let text = await response.text();
console.log('Response body: ', response.status, response.headers, text, response.body);
return response;
});
let [err, visit] = await trygo(browser.visit("/")).catch(e => [e]);
if (err && err.message.startsWith("Server returned status code 401")) {
console.log("auth failed!");
}
text is quite happily getting the content of the response... but how can I update the body?
Maybe this is just a documentation nit and I can just get at the parser, or independently install jsdom and update body... but I suspect that will still result in zombie erroring because of the 401.
First - this is very cool. Good job.
Summary ask: can you expose the parser API somehow so it's possible to parse a response and update a response.body to stop errors caused by status codes?
Background: I am testing an authentication framework that returns the login page in the content body of the response which has status 401.
This is perfectly legal and acceptable thing to do, as you know, most responses with a body will have that displayed rather than the browser default if they're present.
zombie doesn't do that though, I just get an error.
That seems like a good default given zombie's domain. But it would be nice to be able to use a pipeline to make the behaviour the same as a browser.
I looked at pipeline and this is possible:
text is quite happily getting the content of the response... but how can I update the body?
Maybe this is just a documentation nit and I can just get at the parser, or independently install jsdom and update body... but I suspect that will still result in zombie erroring because of the 401.