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

fileserver: Support precompressed files without base files #5745

Closed
wants to merge 3 commits into from

Conversation

singhalkarun
Copy link
Contributor

@singhalkarun singhalkarun commented Aug 14, 2023

Closes #5116

Changes done so far:

  1. Added a new bool value to the FileServer Struct called PreferPrecompressed
  2. Start accepting prefer_precompressed subdirective under the fileserver directive
  3. If PreCompressed is enabed on fileserver, ignore checking the existence of the original file and serve encoded file as per the accepted encoding if available, else return 404.

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

…mpressed

2. Start accepting prefer_precompressed subdirective under the fileserver directive
@CLAassistant
Copy link

CLAassistant commented Aug 14, 2023

CLA assistant check
All committers have signed the CLA.

…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.
@singhalkarun
Copy link
Contributor Author

Hi @francislavoie looking forward for your feedback on the above commits before I proceed with further work. Can you please have a look?

@mholt
Copy link
Member

mholt commented Aug 14, 2023

Thanks for the enhancement!

This is looking pretty good.

I am not quite sure about this, though:

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.

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.
@singhalkarun
Copy link
Contributor Author

singhalkarun commented Aug 15, 2023

Is this something we should actually do? And if so, is 404 the right status code?

Not very sure on this. But considering the main discussion thread (https://caddy.community/t/precompressed-files-without-base-files/17330),

  1. We should be able to serve the file even if the precompressed version doesn't exist (This is already solved by the PR)
  2. If the client doesn't support compressed version, we should decompress and serve (This is yet to be solved which can be discussed over)

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

@francislavoie @mholt

@singhalkarun singhalkarun marked this pull request as ready for review August 15, 2023 22:12
Copy link
Member

@mholt mholt left a 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"`
Copy link
Member

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).

Copy link
Contributor Author

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.

@singhalkarun
Copy link
Contributor Author

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!

Sure, let me add test cases.

@mholt
Copy link
Member

mholt commented Sep 7, 2023

@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)

Copy link
Member

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

Suggested change

Comment on lines -399 to -400
fsrv.logger.Debug("opening file", zap.String("filename", filename))

Copy link
Member

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.

@singhalkarun
Copy link
Contributor Author

@singhalkarun I think we're almost done with this. Any interest in finishing it up?

@mholt Sorry, got occupied with other things. Can I work on this after 15 Sep if it works?

@mholt
Copy link
Member

mholt commented Sep 8, 2023

Yeah, absolutely. I just wanted to check in for status. 👌

@francislavoie francislavoie changed the title Support "precompressed" files without "base" files (#5116) fileserver: Support precompressed files without base files Sep 8, 2023
@francislavoie francislavoie added the feature ⚙️ New feature or request label Sep 8, 2023
@francislavoie francislavoie added this to the 2.x milestone Sep 8, 2023
@mholt
Copy link
Member

mholt commented Apr 18, 2024

@singhalkarun Just wanted to check in one more time, wondering if you're still interested in this.

@singhalkarun
Copy link
Contributor Author

Thanks for the enhancement!

This is looking pretty good.

I am not quite sure about this, though:

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.

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.

Hi @mholt I would like to pass this one for now due to time constraints. Thanks.

@mholt
Copy link
Member

mholt commented Apr 18, 2024

Alrighty, thanks for the update.

@mholt mholt closed this Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "precompressed" files without "base" files
4 participants