Skip to content
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

Initial migration from request to got for http-request node #2952

Merged
merged 6 commits into from
Jun 8, 2021
Merged

Conversation

knolleary
Copy link
Member

Proposed changes

This migrates the HTTP Request node to use the got module in place of the deprecated request module - #2481

I have got to the point where the unit tests pass except for:

  • Proxy handling. I have implemented proxy handling as per the got docs, but I can't get it to work yet. I have raised socket hang up error when using with got and http-proxy delvedor/hpagent#19 to try to make some progress. But may need to look at an alternative approach.
  • keepAlive - we don't have unit tests for this... but I know I haven't implemented it yet. It is tied up with the proxy handling somewhat as they both require replacing the HTTP Agent used by got.

I suspect there will be other edge cases where things have changed - particularly around how errors are reported. But this is a good start.

node.metric("size.bytes", msg, res.client.bytesRead);
}
got(url,opts).then(res => {
msg.statusCode = res.statusCode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I think that @k-toumura said before, we would like to need the starting and ending time of the http request when we investigate logs of Node-RED flow to call REST APIs. We found that the got module is suitable to fill the requirement. Can we add the code like the following to output trace log?

log.trace('http request: nodeid=' + this.id + ' _msgid=' + msg._msgid
        + ' url=' + res.url + ' start=' + res.timings.start + ' end=' + res.timings.end);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We can also extend metric logs, such as:
node.metric("duration.millis", msg, res.timings.phases.total);
node.metric("duration.wait.millis", msg, res.timings.phases.wait);
//... and others (dns, tcp, tls, request, firstByte, download)
  • If httprequest node emit a message that contains entire timings object, following nodes can use this timing values in application (or use them for debugging purpose).
msg.timings = res.timings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware the current code doesn't yet do the metrics reporting the old node did. That is on my list to fix and yes, got makes it much easier to do then the old code.

But I'm not sure about adding timings to the message - we don't do that with any other node. I'm also not keen in exposing things the module gives us directly - because if we ever have to move off the got module, then it's even more work to reproduce the same behaviour.

As it stands, we're still blocked on this PR until we can get proxy support working. The issue i had raised on hpagent has not been answered - so need to look at a different plan for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@knolleary @k-toumura Thank you for your comments. After supporting proxy in the new http request node, we can test it using our corporate proxy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be optional behind the metrics option in settings ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could, but that doesn't change the fact it's becomes part of the public API of the node and puts us on the hook to ensure its always there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not so much if it's only there for debug. - yes if it there for daily operation.

@hardillb
Copy link
Member

hardillb commented May 10, 2021

Progress, I have proxying working but not if there is a redirect to SSL (actually even without the proxy it fails a redirect on my domain)

Also it looks to be appending the the proxy port to the end of the URL in msg.responseURL

@hardillb
Copy link
Member

If I apply the fix from delvedor/hpagent#18 then proxying is working for me with a local Squid instance.

msg.statusCode = res.statusCode;
msg.headers = res.headers;
let hostname = res.req.host;
if (res.req.protocol === "http:" && res.socket.remotePort !== 80) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is picking up the port number from the proxy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this in #2986

@hardillb
Copy link
Member

@k-toumura I think I have proxy support working, there is a fork of this branch here if you would like to test

Get got working with proxies
@hardillb
Copy link
Member

One thing I have noticed is that the hpagent uses the CONNECT verb for all connection, so the proxy never gets to cache and some proxies might be configured not to support CONNECT for none HTTPS connections. Will need to remember to look out for that. There is a hpagent bug asking for cache support (but it's been unanswered since Feb 2021).

The original version would pick up the proxy servers port number
@hardillb
Copy link
Member

I'm 95% sure the test failures are to do with the hpagent only using CONNECT to request content directly from the original target rather than from the cache

@knolleary
Copy link
Member Author

Merging as-is - with more work on the proxy tests to follow

@knolleary knolleary merged commit 7bf9389 into dev Jun 8, 2021
@kazuhitoyokoi
Copy link
Member

http request node in the current dev branch returns HTTP 400 when using our corporate proxy. The first example using http module and got example in the hpagent documentation also don't work in our environment. I will discuss it with my colleagues tomorrow.

@knolleary
Copy link
Member Author

@kazuhitoyokoi thanks for letting us know. We'll go ahead with the beta release with a warning about the proxy support not being there yet. If there's debugging you can do to help track down a fix, that would be appreciated.

@hardillb
Copy link
Member

When testing can you try a mix of http and https sites and also let us know how the proxy is setup:

  • Are you setting the env var or using the config node to set up the proxy?
  • Do you need to supply a username/password for the proxy?

Also is the proxy accessed via http or https? And if possible some wireshark/network capture logs might help

@kazuhitoyokoi
Copy link
Member

@hardillb I submitted the issue (#3016) to answer all of the questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Node-RED 2.0 Planning
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

5 participants