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

client breaking: add initial version of client handlers #449

Draft
wants to merge 1 commit into
base: 0.3.x
Choose a base branch
from

Conversation

jbr
Copy link
Contributor

@jbr jbr commented Dec 4, 2023

No description provided.

client/src/cookies.rs Fixed Show fixed Hide fixed
client/src/cookies.rs Fixed Show fixed Hide fixed
Copy link

codecov bot commented Dec 4, 2023

Codecov Report

Attention: 109 lines in your changes are missing coverage. Please review.

Comparison is base (a1a6147) 47.96% compared to head (e0545e0) 47.32%.

Files Patch % Lines
client/src/follow_redirects.rs 0.00% 23 Missing ⚠️
client/src/client_handler.rs 0.00% 20 Missing ⚠️
client/src/conn.rs 23.07% 20 Missing ⚠️
client/src/cookies.rs 0.00% 20 Missing ⚠️
client/src/expect_status.rs 0.00% 18 Missing ⚠️
client/src/client.rs 76.92% 3 Missing ⚠️
client/src/client_like.rs 0.00% 2 Missing ⚠️
server-common/src/client.rs 50.00% 2 Missing ⚠️
http/src/headers/known_header_name.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #449      +/-   ##
==========================================
- Coverage   47.96%   47.32%   -0.64%     
==========================================
  Files         169      173       +4     
  Lines        6569     6683     +114     
==========================================
+ Hits         3151     3163      +12     
- Misses       3418     3520     +102     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

client/src/cookies.rs Fixed Show fixed Hide fixed
client/src/conn.rs Fixed Show fixed Hide fixed
use trillium_server_common::async_trait;

#[async_trait]
pub trait ClientHandler: std::fmt::Debug + Send + Sync + 'static {

Check warning

Code scanning / clippy

missing documentation for a trait Warning

missing documentation for a trait

#[async_trait]
pub trait ClientHandler: std::fmt::Debug + Send + Sync + 'static {
async fn before(&self, conn: &mut Conn) -> crate::Result<()> {

Check warning

Code scanning / clippy

missing documentation for a method Warning

missing documentation for a method
Ok(())
}

async fn after(&self, conn: &mut Conn) -> crate::Result<()> {

Check warning

Code scanning / clippy

missing documentation for a method Warning

missing documentation for a method
Ok(())
}

fn name(&self) -> Cow<'static, str> {

Check warning

Code scanning / clippy

missing documentation for a method Warning

missing documentation for a method
client/src/conn.rs Fixed Show fixed Hide fixed
use crate::{async_trait, client_handler::ClientHandler, Conn, KnownHeaderName, Result};

#[derive(Debug, Default, Copy, Clone)]
pub struct FollowRedirects {

Check warning

Code scanning / clippy

missing documentation for a struct Warning

missing documentation for a struct
client/src/follow_redirects.rs Fixed Show fixed Hide fixed
client/src/follow_redirects.rs Fixed Show fixed Hide fixed
@@ -0,0 +1,63 @@
use crate::{async_trait, client_handler::ClientHandler, Conn, Error, KnownHeaderName, Result};
use std::mem;

Check warning

Code scanning / clippy

unused import: std::mem Warning

unused import: std::mem
}

impl FollowRedirects {
pub fn new() -> Self {

Check warning

Code scanning / clippy

missing documentation for an associated function Warning

missing documentation for an associated function
}

#[derive(Default, Debug)]
pub struct RedirectHistory(Vec<Url>);

Check warning

Code scanning / clippy

missing documentation for a struct Warning

missing documentation for a struct
@@ -11,7 +11,9 @@ keywords = ["trillium", "framework", "async"]
categories = ["web-programming", "web-programming::http-client"]

[features]
json = ["serde_json", "serde", "thiserror"]
default = ["cookies", "json"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider making cookies not be enabled by default. Based on previous experience with tide, once crates in the ecosystem start depending on trillium-client, it's really hard to get all of them using default-features = false, even though many won't need this.

I know that trillium is going for a "just works" API, but having to enable a feature flag to get a more featureful client doesn't seem like too much to ask here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really useful bit of feedback! My initial inclination was for each client handler be their own crate to make totally clear that it doesn't depend on any private state, but convinced myself to limit the proliferation of tiny trillium-client-* crates. I think I may have overcorrected in the other direction. I'll change them to opt-in instead of opt-out before release, or possibly even go for the trillium-client-cookies, trillium-client-follow-redirects, trillium-client-cache crates

Copy link
Collaborator

@joshtriplett joshtriplett Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbr Perhaps a middle ground might make sense: a single trillium-client-handlers crate for all the handlers that don't add dependencies, and either a separate crate or feature flag (or both with re-export) for handlers that do add dependencies. That should reduce proliferation.

@joshtriplett
Copy link
Collaborator

This looks amazing, and I'm looking forward to trying it out, for things like base URLs and standard headers.

@jbr jbr changed the base branch from main to 0.3.x April 6, 2024 20:52
@jbr jbr force-pushed the 0.3.x branch 2 times, most recently from a126843 to 15029f8 Compare April 7, 2024 02:04
@jbr jbr force-pushed the 0.3.x branch 2 times, most recently from 8f6f77f to 63e23d1 Compare April 17, 2024 21:59
@jbr jbr force-pushed the 0.3.x branch 2 times, most recently from 3fb8da6 to ac4ef28 Compare May 31, 2024 18:38
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.

2 participants