-
Notifications
You must be signed in to change notification settings - Fork 120
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
get response content #136
Comments
See the reference
Please note that responseBody is available only for response request in a subrequest callback. function content(r) {
function callback(response) {
// response.responseBody is available here;
}
r.subrequest('/foo', callback);
} |
but this method works only for subrequest. but what should I do if I don't need to get response of subrequest? for example: I go on site and I want to get the response of this request (i.e. html code) |
@inikonorov |
Thank you very much! |
@drsm @inikonorov How did you get the response body exactly? I am trying to log the response body in a file. This is my js file
I tried above but getting error |
@maniLonkar Subrequests are asynchronous and you should end the main request manually when all or some of them are complete. The return value of function logger(r) {
var time = r.variables.time_local;
var method = r.method;
var uri = r.uri;
var status = r.status;
var reqBody = r.requestBody || {};
var args = r.args == undefined || r.args == null ? {} : r.args;
var session = getSession(r.headersIn);
var log = "";
r.subrequest(uri, function(res) {
r.log("respBody");
r.log(res.responseBody);
r.return(200, JSON.stringify({
"time": time,
"method": method,
"uri": uri,
"status": status,
"req_body": r.requestBody,
"session": session,
"resp_body": "res.responseBody",
});
}));
} |
I've managed to get full response body content using js_body_filter, that later can be used for logging, example is here - https://github.com/dmitry-j-mikhin/nginx-njs-log |
@dmitry-j-mikhin It worked thanks |
How can I get content of response in njs?
The text was updated successfully, but these errors were encountered: