-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix #19294, Ruby NetHttpRequest improvements #20101
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
Conversation
* | ||
* # connection re-use | ||
* Net::HTTP.start("http://example.com") do |http| | ||
* http.get("/") | ||
* end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that technically Net::HTTP.new
does not open/reuse connections/sessions: https://docs.ruby-lang.org/en/master/Net/HTTP.html#method-c-new
http = Net::HTTP.new("https://example.com") | ||
root_get = Net::HTTP::Get.new("/") | ||
http.request(root_get) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case was already detected without the above code modifications, but I wanted to make sure that request objects are also detected correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution; changes look good to me, only minor changes needed.
@@ -30,20 +37,27 @@ class NetHttpRequest extends Http::Client::Request::Range instanceof DataFlow::C | |||
| | |||
// Net::HTTP.get(...) | |||
method in ["get", "get_response"] and | |||
requestNode = API::getTopLevelMember("Net").getMember("HTTP").getReturn(method) and | |||
connectionNode = API::getTopLevelMember("Net").getMember("HTTP") and | |||
requestNode = connectionNode.getReturn(method) and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move requestNode = connectionNode.getReturn(method)
up after line 36, and then remove the three duplicated lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's curious to me that you can set requestNode
before you've set connectionNode
in this situation. I've made the requested change, but I'd like to learn more. Is there some documentation you can point me to describing this behavior, or is that "just the way it works" with queries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QL is a logic language, so you should not think of x = y
as an assignment, but rather as a constraint (x
must be equal to y
). So the order doesn't really matter.
* ``` | ||
*/ | ||
class NetHttpRequest extends Http::Client::Request::Range instanceof DataFlow::CallNode { | ||
private DataFlow::CallNode request; | ||
private API::Node requestNode; | ||
API::Node requestNode; | ||
API::Node connectionNode; |
Check notice
Code scanning / CodeQL
Field only used in CharPred Note
This PR makes 3 improvements to the
NetHttpRequest
class:connectionNode
like other Ruby HTTP clients (see Ruby NetHttpRequest improvements #19294)requestNode
andconnectionNode
public so subclasses can use them (see Ruby NetHttpRequest improvements #19294)Net::HTTP.start
- this is a common way to make HTTP requests in Ruby