[EDIT 22/10/2018: the title has been changed to node-red-contrib-http-logger, since we agreed in the discussion below that node-red-contrib-http-listener would be confusing ...
Hi folks,
From time to time we get questions on this forum similar to this one:
I can connect with my browser to my IP camera without problems. However when I use the same URL / username / password in Node-RED, this doesn't work.
Since Node-RED gets a difference response from the camera, it means that Node-RED sends a different request to the camera. But what is the difference between the request from Node-RED and the request from the browser, which causes the failure ...
The user can easily see the browser request in his browser developer tools, but the Node-RED requests will be created by NodeJS behind the scenes (invisible for the user).
Last week somebody asked me such a question, so I had only a limited set of options:
- Start guessing what Node-RED is requesting. Not my cup of tea ...
- Ask the user to install some third party tool (e.g. Wireshark ...), but less-technical users would interpret this as 'Bugger off and leave me alone ...'.
- Ask the user to make the IP camera public on his router, and debug remotely to determine what is going on.
- Find a way to let the user intercept the http(s) requests and responses via Node-RED (without the need of using extra third-party tools).
I prefer option 4, which has resulted in the new node-red-contrib-http-listener node. Until it is published on NPM, you can install it directly from Github:
npm install bartbutenaers/node-red-contrib-http-listener
Here is a short demo to give a first impression:
I have some questions, so all 'constructive' feedback is very welcome!
-
The underlying request emits a 'success' or an 'error' event. Currently I generate output messages with two different topics ('success' or 'error'). Or should I use two outputs on my node, one for success requests and one for error requests. Or should I use another solution ...
-
The user can limit the number of output messages by filtering on URL (see readme for example). Currently if you pass as filter 'abc' all requests whose URL contains this text will be passed. For example _´http://www.abcdef.com:1234/somepath´_ will be passed. Did it this way because I assume that regular expressions are a bit overwhelming for some users. Any other suggestions?
PS. I want to do the filtering INSIDE this node (instead of adding an extra filter node BEHIND it) to avoid overloading Node-RED with too much messages...
-
Currently I don't see a way to get the raw request, as required in some other posts (e.g. this one). If somebody has an idea how to accomplish that, please let me know so I could add an extra option to this node.
P.S. I use under the hood the global-request-logger module, which replaces the standard NodeJs request method by its own wrapper:
http.request = attachLoggersToRequest.bind(http, 'http');
And that function calls in turn NodeJs's original request function:
function attachLoggersToRequest(protocol, options, callback) { let self = this; let req = ORIGINALS[protocol].request.call(self, options, callback);
So perhaps we could intercept somewhere in this area the raw request. Had no time to investigate this in more detail ...
-
I noticed that sometimes not all requests are displayed. E.g. when
setImmediately=false
in the HttpRequest node (see explanation from Nick), then only the first request is displayed (which is responded by 'unauthorised'). However the second request is not displayed. Will need to investigate that once I'm retired... -
Other ideas or suggestions??
Thanks !
Bart