Skip to content
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

Add ability to create a new WebPushClient from a custom Isahc/hyper client (#56) #57

Merged
merged 2 commits into from
May 3, 2024

Conversation

naskya
Copy link
Contributor

@naskya naskya commented Apr 29, 2024

@andyblarblar
Copy link
Collaborator

Thanks for the contribution! Would you mind removing the unused import causing the CI to fail? I don't think this is actually from your changes, but either way it would be nice to fix while we're here.

@naskya
Copy link
Contributor Author

naskya commented Apr 30, 2024

Okay! I applied the fixes suggested by cargo clippy.

Clippy also warned me that this response is ()

let response = client.send(builder.build()?).await?;
println!("Sent: {:?}", response);

because send returns Result<(), WebPushError>

async fn send(&self, message: WebPushMessage) -> Result<(), WebPushError> {

which comes from request_builder::parse_response.

let response = request_builder::parse_response(response_status, body.to_vec());
debug!("Response: {:?}", response);
if let Err(WebPushError::ServerError(None)) = response {
Err(WebPushError::ServerError(retry_after))
} else {
Ok(response?)
}

/// Parses the response from the push service, and will return `Err` if the request was bad.
pub fn parse_response(response_status: StatusCode, body: Vec<u8>) -> Result<(), WebPushError> {

Part of me wonders if this is unintentional and you may actually want to return http::Response rather than (), but a function in the unit test implies this is intentional, so I’m not quite sure how I should fix this.

#[test]
fn parses_a_successful_response_correctly() {
assert_eq!(Ok(()), parse_response(StatusCode::OK, vec![]))
}

@naskya
Copy link
Contributor Author

naskya commented May 2, 2024

Having said that, changing the return value of a function would cause a breaking change, and it may be too much to address that warning in this single merge request, so I personally think we should ignore it for now.

@andyblarblar
Copy link
Collaborator

Yeah, I agree. I think it's a reasonable pattern to use to just use a Result with a Unit in the Ok when you only want to indicate an error, but the way the code is used here is odd. Given the functions docs and the unit test it does look like this is intential, and the function is just used to check for bad HTTP codes. Not ideal, but pretty niche tbh given how this library is normally used.

Now that all the CI passes, I'll merge this in. Thanks for the help again!

@andyblarblar andyblarblar merged commit 40febe4 into pimeys:master May 3, 2024
11 checks passed
@naskya naskya deleted the feat/custom-client branch May 3, 2024 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: add ability to use proxy
2 participants