-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix compression middleware images #2996
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
base: master
Are you sure you want to change the base?
Fix compression middleware images #2996
Conversation
The solution to this issue should allow user customization of the excluded mime types. |
Thanks, I will take it mind. |
So, I was taking a look into the #[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Compress {
pub compress: fn(Mime) -> bool,
}
impl Default for Compress {
fn default() -> Self {
Compress {
compress: |_| { true }
}
}
} |
Use of a predicate function is a good idea imo. Then we just set the default to ignore images to solve #2981. |
Only one question for the moment @robjtede. How do we return an uncompressed response?. After skimming through the code. I believe the decision to compress or not should be done in the |
@robjtede I was able to add a proof of concept of using a predicate function for deciding whether or not to compress based on the value of the Content-Type header of the response. I think there are points to improve though the first one is that currently the |
@cptrodolfox I spent some time working on this PR today but I can't push to your branch. Can you check the settings for this PR? Alternatively, apply this patch here: 0216cb1 |
Hey @robjtede, It appears since the fork is from a organization I can not change the "Allow edit from maintainers" setting. I will apply manually the patch you mentioned. |
Hey @robjtede , I have added the changes you made. I look through the changes. And, If you don't mind, I want to ask you the following: What is the idea behind using a counted reference for |
The advantage over taking a function pointer is that you can still avoid the generic param and also pass closures as well. |
Thanks for the answer. |
Should be noted that some auto traits are lost in this PR, wondering if this is okay.
|
I am unsure if losing these traits would affect users down stream. If so we might want to implement them, manually. WDYT @robjtede |
From the rebase this needs a rustfmt run. On the blocker for merging this, I'd be willing to give up the UnwindSafe impls but not so much Send and Sync, unfortunately. I can definitely think of common patterns where it would break and that's not acceptable. Thinking about how to progress, though it'll probably just be holding off until v5.0 for the customization part and we backpace this PR to just solve the original issue and emulate the "default" behavior. |
I've created #3075 with the subset of changes that do not cause breakage to the public API. |
PR Type
Adds predicate for compression of responses with default value that skips compression for video and images.
PR Checklist
Overview
Closes #2981