Joe_Reifel
Sep 13, 2013Employee
Scripting: what is the response object used for when processing a request?
This may be a "RTM" question but here goes. The docs on lineratesystems.com do a good job at explaining how to use the HTTP request object. And I believe that the response object is for manipulating (or setting) what the LineRate will send back to the client.
So my question is how do I get at the server response?
Abridged code with my question in the middle:
var vsm = require('lrs/virtualServerModule');
var vs; // will be assigned in onRequest
var pidinfo = "(PID " + process.pid + "): ";
// Log to a database
var connection = mysql.createConnection({
<>
});
var onRequest = function(request, response, next ) {
// do some processing
// Add the record to the database automatically if they don't already exist
// Here I would store the time (in ms) that the connection came in
connection.query('INSERT INTO urls (uri) select * FROM (SELECT "' + connection.escape(request.url) + '") as tmp \
WHERE NOT EXISTS(SELECT uri from urls where uri="' + connection.escape(request.url) + '")', function(err, rows, fields) {
if (err) throw err;
// Here we make the server pick
connection.query('SELECT opt_in from urls where uri="' + connection.escape(request.url) + '"', function(err, rows, fields) {
if (err) throw err;
var opt_in = rows[0].opt_in;
if( !opt_in ) {
// HERE IS WHERE MY QUESTION IS - where does the response go, and how can I hook into it so I can process the other timestamp?
vs_a.newRequest(request, response, next);
return;
} else {
vs_b.newRequest(request, response, next);
return;
}
});
});
};
// onRequest
var onExist = function(the_vs) {
if(the_vs.id == 'Bugzilla') {
connection.connect();
console.log( pidinfo + "Database connected.");
logged_in = true;
vs = the_vs;
vs.on('request', onRequest);
}
};
vsm.on('exist', 'Bugzilla', onExist);