-
Notifications
You must be signed in to change notification settings - Fork 183
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
Implement digest authentication middleware behind a feature flag #468
Implement digest authentication middleware behind a feature flag #468
Conversation
Co-authored-by: Matěj Laitl <[email protected]>
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.
For what it's worth, looks good to me!
Today I've learned that cases in stc/test/*
are called integration tests, so calling external sites may be actually appropriate there.
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.
@PabloMansanet welcome to ureq!
This looks good, and I do welcome that we have some standard middleware in the main crate. I left a couple of notes in the code and here are some more.
- Please make changes
.github/workflows/test.yml
to ensure the new feature flag is being automatically tested. - Similarly please update
test.sh
(this is what we use for local dev to roughly do what github actions do). - We need to update
lib.rs
documentation for feature flags (and runcargo readme
to generate a new README.md)
Bigger picture discussion, maybe @jsha could input?
- Feature flags for middleware are good. No need to compile them if they are not wanted.
- These feature flags are different to the others we have because they require the user to both enable the feature flag AND configure the agent with the middleware.
- Maybe we should have a separate section in README.md detailing how to use optional middleware?
- Since we're likely to have a couple more of these. I wonder if we should group them by some prefix. Like
mw-digest-auth
,mw-basic-auth
src/middleware.rs
Outdated
/// | ||
/// let agent = ureq::AgentBuilder::new().middleware(digest_auth_middleware).build(); | ||
/// agent.get(&url).call(); | ||
/// ``` |
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.
Look in the crate for how we construct doc tests against httpbin.org
, but actually wrapping them to also work offline.
It would be nice if this test actually checked the returned headers (from httpbin.org) to verify the digest worked as expected.
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.
@algesten thanks for the hint! I've looked into it, but I'm still not sure how it works. I see that those doctests call the function ureq::is_test(true)
, but other than that they seem to be contacting httpbin.org
normally. Am I missing something? Do you have a file/line number for an example of that httpbin.org
wrapping? Thanks!
Thanks for the review @algesten. All the proposed changes make sense so I'll ping when I'm done with them 🙂 |
While testing this middleware on the field, we've noticed an issue that might be difficult to solve with the current Middleware API. Basically, while this works well for GET requests, anything with a payload is tricky because the middleware has no access to the payload from what I can see. Starting a request with Is it conceivable to solve this kind of problem through a change in the There was a similar issue around 307/308 responses, and the conclusion seems to be that PUT/POST/DELETE "retries" have to be handled at application level. Is this still the expectation, or can we possibly solve this at the middleware level for non-stream payloads? |
Hey! Thanks for fixing those things!
As you correctly pointed out, this is very similar to handling 307/308 with body. I'm trying to think if there is some quick win here without handling streaming bodies. let response = next.handle(request.clone())?; Here we would need something else, maybe something along the lines of: // Buffer request bodies up to 10k
request.resend_buffer(10_000);
let response = next.handle(request)?;
...
if let Some((mut request, body)) = response.take_resend() {
request.set("Authorization", "Bar");
request.resend(body);
} The idea is that |
Oh for the failed lint, do you mind running |
No activity. Feel free to reopen or start new PR. |
Didn't mean to close this. |
bd2fabb
to
93c9362
Compare
Closing this since we're moving to 3.x |
In #392 , @algesten mentioned that it could be possible to consider default middleware for common features like Digest authentication. Here's a simple implementation, in case it's general enough to add to the main crate.
Some thoughts:
digest
. Is this a good approach?Arc<Mutex<>>
state in the middleware itself, but this may be erring on the "too smart" side. I don't directly see any problems it might cause but I could definitely be missing some.