-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fileserver: Support precompressed
files without base files
#5745
Conversation
…mpressed 2. Start accepting prefer_precompressed subdirective under the fileserver directive
…tence of the original file and serve encoded file as per the accepted encoding if available, else return 404. To Do Next: If the file is not available as per accepted encoding, try to decompress the encoded file to original file and serve, if not able to, return 404.
Hi @francislavoie looking forward for your feedback on the above commits before I proceed with further work. Can you please have a look? |
Thanks for the enhancement! This is looking pretty good. I am not quite sure about this, though:
Is this something we should actually do? And if so, is 404 the right status code? Note: We're on feature freeze until 2.9 development, so even if this gets merged soon it likely won't get released until after 2.8. |
…compressedInfo 2. Fixed an issue when the PreCompressed parameter is enabled and the original file is also present, need to fetch the FileInfo such that it can be used in ServeContent.
Not very sure on this. But considering the main discussion thread (https://caddy.community/t/precompressed-files-without-base-files/17330),
For now, let me convert the draft PR to a normal PR and I'll open a separate PR that handles the 2nd scenario and we can continue the discussion over there. Associated with #5116 |
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.
Thanks for this feature. I think it's looking pretty good, but I haven't done a thorough inspection or tried it yet.
It might be best to add a test case (an integration test) that verifies it works.
Then we'll get this merged in for ~2.9!
@@ -132,6 +132,8 @@ type FileServer struct { | |||
// clobbering the explicit rewrite with implicit behavior. | |||
CanonicalURIs *bool `json:"canonical_uris,omitempty"` | |||
|
|||
PreferPrecompressed bool `json:"prefer_precompressed,omitempty"` |
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.
We should add godoc comments to this field, otherwise it'll appear without documentation on the Caddy website (in the JSON config section).
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.
Got it. Let me add the godoc comments to this field.
Sure, let me add test cases. |
@singhalkarun I think we're almost done with this. Any interest in finishing it up? |
@@ -476,6 +492,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c | |||
// that errors generated by ServeContent are written immediately | |||
// to the response, so we cannot handle them (but errors there | |||
// are rare) | |||
|
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.
Don't need this newline anymore
fsrv.logger.Debug("opening file", zap.String("filename", filename)) | ||
|
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.
I think we should preserve the debug log, it's helpful for tracing. In fact, maybe we should add more debug logs in here relating to which file is being picked depending on the precompressed options.
@mholt Sorry, got occupied with other things. Can I work on this after 15 Sep if it works? |
Yeah, absolutely. I just wanted to check in for status. 👌 |
precompressed
files without base files
@singhalkarun Just wanted to check in one more time, wondering if you're still interested in this. |
Hi @mholt I would like to pass this one for now due to time constraints. Thanks. |
Alrighty, thanks for the update. |
Closes #5116
Changes done so far:
To Do:
If the file is not available as per accepted encoding, try to decompress the encoded file to original file and serve, if not able to, return 404. (Not handling this in current PR, will be opening a new PR for this.)
@francislavoie