According to the documentation it should be possible to use either a String or a Buffer instance when using r.send() to send part of the response to the client.
If I try to send a Buffer, the request fails and I see an error in the log:
js exception: TypeError: Cannot convert object to primitive value
Here's is my example handler that I'm trying to use with the js_content directive:
function handler(req) {
req.status = 200;
req.sendHeader();
req.send(Buffer.from('mystring'));
req.finish();
}
Sending a String instead of a Buffer with r.send("mystring") works fine. Sending the entire response as a buffer using r.return(200, Buffer.from('mystring')) seems to work fine as well.
According to the documentation it should be possible to use either a String or a Buffer instance when using
r.send()
to send part of the response to the client.If I try to send a Buffer, the request fails and I see an error in the log:
Here's is my example handler that I'm trying to use with the
js_content
directive:Sending a String instead of a Buffer with
r.send("mystring")
works fine. Sending the entire response as a buffer usingr.return(200, Buffer.from('mystring'))
seems to work fine as well.I'm using njs 0.8.3 with nginx 1.24.0.