-
Notifications
You must be signed in to change notification settings - Fork 202
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
feat: multiple onRequest handlers #1863
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1863 +/- ##
==========================================
- Coverage 82.70% 82.53% -0.17%
==========================================
Files 177 178 +1
Lines 18051 18215 +164
==========================================
+ Hits 14929 15034 +105
- Misses 3122 3181 +59 ☔ View full report in Codecov by Sentry. |
f7ab336
to
f9669b7
Compare
Action required: PR inactive for 2 days. |
@webbdays Can you please resolve the conflicts. |
Whenever you are ready, just mark it as ready to review. |
ok. |
Bencher
🚨 1 ALERT: Threshold Boundary Limit exceeded!
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
headers, | ||
body: Bytes::default(), | ||
}), | ||
} |
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.
Can we just call execute
here? There is quite a bit of code duplication.
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.
yes
@@ -65,6 +65,7 @@ impl Loader<DataLoaderRequest> for HttpDataLoader { | |||
async fn load( | |||
&self, | |||
keys: &[DataLoaderRequest], | |||
http_filter: HttpFilter, |
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.
Store the filter in HttpDataLoader
as a field
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.
Can you please explain more. Where is it used later in the code?
src/core/http/filter.rs
Outdated
#[derive(Default, Clone, Debug)] | ||
/// User can configure the filter/interceptor | ||
/// for the http requests. | ||
pub struct HttpFilter { | ||
pub on_request: Option<String>, | ||
} |
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.
can delete this file. Move it to http
module.
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.
Ok.
let req = req_template.to_request(&ctx)?; | ||
let is_get = req.method() == reqwest::Method::GET; | ||
|
||
let res = if is_get && ctx.request_ctx.is_batching_enabled() { | ||
let data_loader: Option<&DataLoader<DataLoaderRequest, HttpDataLoader>> = | ||
dl_id.and_then(|index| ctx.request_ctx.http_data_loaders.get(index.0)); | ||
execute_request_with_dl(&ctx, req, data_loader).await? | ||
execute_request_with_dl(&ctx, req, data_loader, http_filter.clone()).await? |
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 is hot path. Let's not perform any clones here. Pass the filter as a reference.
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.
ok.
@@ -27,6 +27,7 @@ pub enum IO { | |||
req_template: http::RequestTemplate, | |||
group_by: Option<GroupBy>, | |||
dl_id: Option<DataLoaderId>, | |||
http_filter: HttpFilter, |
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 could be optional. If not specified, we should not unnecessarily make a round trip to the JS runtime.
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.
if we dont have/want ant filter then we pass HttpFilter::default(). WE have a check in request Filter logic to call onRequest or execute directly.
&self, | ||
req: reqwest::Request, | ||
_http_filter: &'life0 HttpFilter, | ||
) -> anyhow::Result<Response<Bytes>> { |
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.
Too much code here, can we reuse execute?
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.
ok.
.await?; | ||
tracing::info!("{} {} {}", method, url, res.status.as_u16()); | ||
Ok(res) | ||
} |
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.
We should just call execute here.
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.
ok.
let res = Response::from_reqwest(response).await?; | ||
tracing::info!("{} {}", req_str, res.status.as_u16()); | ||
Ok(res) | ||
} |
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.
just call execute here.
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.
ok.
if !http.group_by.is_empty() && http.method == Method::GET { | ||
Expression::IO(IO::Http { | ||
req_template, | ||
group_by: Some(GroupBy::new(http.group_by.clone())), | ||
dl_id: None, | ||
http_filter, |
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.
Filter should be optional
src/core/http/mod.rs
Outdated
/// User can configure the filter/interceptor | ||
/// for the http requests. | ||
pub struct HttpFilter { | ||
pub on_request: Option<String>, |
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.
I think on_request
should not be optional. There is no utility a HttpFilter that doesn't have any on_request.
Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
Action required: PR inactive for 2 days. |
# Conflicts: # src/cli/javascript/request_filter.rs
Action required: PR inactive for 2 days. |
Summary:
multiple onRequest handlers
Issue Reference(s):
Fixes #1271
Build & Testing:
cargo test
successfully../lint.sh --mode=fix
to fix all linting issues raised by./lint.sh --mode=check
.Checklist:
<type>(<optional scope>): <title>