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
Issue-6642 Add http.send request attribute to ignore headers for caching key #6675
base: main
Are you sure you want to change the base?
Changes from 2 commits
1c9b35d
81c75e9
4bcaa77
06c7372
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1012,6 +1012,46 @@ func TestHTTPSendCaching(t *testing.T) { | |
response: `{"x": 1}`, | ||
expectedReqCount: 3, | ||
}, | ||
{ | ||
note: "http.send GET different headers but still cached because ignored", | ||
ruleTemplate: `p = x { | ||
r1 = http.send({"method": "get", "url": "%URL%", "force_json_decode": true, "headers": {"h1": "v1", "h2": "v2"}, "cache_ignored_headers": ["h2"]}) | ||
r2 = http.send({"method": "get", "url": "%URL%", "force_json_decode": true, "headers": {"h1": "v1", "h2": "v3"}, "cache_ignored_headers": ["h2"]}) # cached | ||
x = r1.body | ||
}`, | ||
response: `{"x": 1}`, | ||
expectedReqCount: 1, | ||
}, | ||
{ | ||
note: "http.send GET cache miss different headers (force_cache enabled)", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what scenario in the changes is this test case trying to exercise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to clarify how cache behaves when |
||
ruleTemplate: `p = x { | ||
r1 = http.send({"method": "get", "url": "%URL%", "force_json_decode": true, "headers": {"h1": "v1", "h2": "v2"}, "force_cache": true, "force_cache_duration_seconds": 300}) | ||
r2 = http.send({"method": "get", "url": "%URL%", "force_json_decode": true, "headers": {"h1": "v1", "h2": "v3"}, "force_cache": true, "force_cache_duration_seconds": 300}) | ||
x = r1.body | ||
}`, | ||
response: `{"x": 1}`, | ||
expectedReqCount: 2, | ||
}, | ||
{ | ||
note: "http.send GET different headers but still cached because ignored (force_cache enabled)", | ||
ruleTemplate: `p = x { | ||
r1 = http.send({"method": "get", "url": "%URL%", "force_json_decode": true, "headers": {"h1": "v1", "h2": "v2"}, "force_cache": true, "force_cache_duration_seconds": 300, "cache_ignored_headers": ["h2"]}) | ||
r2 = http.send({"method": "get", "url": "%URL%", "force_json_decode": true, "headers": {"h1": "v1", "h2": "v3"}, "force_cache": true, "force_cache_duration_seconds": 300, "cache_ignored_headers": ["h2"]}) # cached | ||
x = r1.body | ||
}`, | ||
response: `{"x": 1}`, | ||
expectedReqCount: 1, | ||
}, | ||
{ | ||
note: "http.send GET different cache_ignored_headers but still cached (force_cache enabled)", | ||
ruleTemplate: `p = x { | ||
r1 = http.send({"method": "get", "url": "%URL%", "force_json_decode": true, "headers": {"h1": "v1", "h2": "v2"}, "force_cache": true, "force_cache_duration_seconds": 300, "cache_ignored_headers": ["h2"]}) | ||
r2 = http.send({"method": "get", "url": "%URL%", "force_json_decode": true, "headers": {"h1": "v1", "h2": "v2"}, "force_cache": true, "force_cache_duration_seconds": 300, "cache_ignored_headers": ["h2", "h3"]}) # cached | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for testing we can actually have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also a test for the scenario when the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more case I can think of: R1: {"headers": {"h1": "v1"}} So here R1 and R2 are equivalent, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another one: R1: {"headers": {"h1": "v1"}, "cache_ignored_headers": []} So here R1 and R2 are equivalent, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
x = r1.body | ||
}`, | ||
response: `{"x": 1}`, | ||
expectedReqCount: 1, | ||
}, | ||
{ | ||
note: "http.send POST cache miss different body", | ||
ruleTemplate: `p = x { | ||
|
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.
Nit: We can do an early exit here