maoertel / diqwest

Crate to extend `reqwest` to be able to send with digest auth flow.
https://docs.rs/diqwest
MIT License
18 stars 3 forks source link

Query parameters being dropped from URI in Authorization header #8

Closed edmonds closed 1 year ago

edmonds commented 1 year ago

Hi @maoertel,

Just following up on #1 and the fix in #4.

I tried upgrading to diqwest 1.1.0 and I see the uri field in the Authorization header is now being reduced to just the URI path, which seems to trim a little too much. I have some query parameters set and the query string is also getting stripped. For the embedded device I'm sending requests to this makes it return a 400.

This patch worked for me:

diff --git a/src/blocking.rs b/src/blocking.rs
index 061be24..d35b553 100644
--- a/src/blocking.rs
+++ b/src/blocking.rs
@@ -23,7 +23,7 @@ impl WithDigestAuth for RequestBuilder {
     match first_response.status() {
       StatusCode::UNAUTHORIZED => {
         let request = clone_request_builder(self)?.build()?;
-        let path = request.url().path();
+        let path = request.url()[url::Position::AfterPort..];
         let method = HttpMethod::from(request.method().as_str());
         let body = request.body().and_then(|b| b.as_bytes());
         let answer = parse_digest_auth_header(first_response.headers(), path, method, body, username, password);
diff --git a/src/lib.rs b/src/lib.rs
index a431830..f8ad652 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -71,7 +71,7 @@ impl WithDigestAuth for RequestBuilder {
     match first_response.status() {
       StatusCode::UNAUTHORIZED => {
         let request = clone_request_builder(self)?.build()?;
-        let path = request.url().path();
+        let path = &request.url()[url::Position::AfterPort..];
         let method = HttpMethod::from(request.method().as_str());
         let body = request.body().and_then(|b| b.as_bytes());
         let answer = parse_digest_auth_header(first_response.headers(), path, method, body, username, password);
maoertel commented 1 year ago

Hey @edmonds,

thanks for reporting, will do my best to take a look this week. 👋🏾