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

Doesn't work when serving from uberjar #3

Open
whmountains opened this issue Jun 15, 2022 · 5 comments
Open

Doesn't work when serving from uberjar #3

whmountains opened this issue Jun 15, 2022 · 5 comments

Comments

@whmountains
Copy link

Files served from an uberjar are instances of JarURLInputStream not File, therefore no etag is calculated.

@danielcompton
Copy link
Member

Patches welcome, or I'll get to this eventually.

@whmountains
Copy link
Author

I tried to make a patch but got hung up on some limitations of my Java interop knowledge. I went for a temporary fix for now but will be happy to submit a patch if I get one working. Cheers.

@uvNikita
Copy link

uvNikita commented Aug 7, 2023

@danielcompton I might be missing something, but it seems that checksum-file works as-is when passed sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream instance.

It even returned the same checksum value as when the file is passed as a File instance.

So I think might just work if modifying the check here to also accept JarURLInputStream or generic InputStream/FileInputStream:

https://github.com/deps-app/ring-etag-middleware/blob/fb26097130d84a38b941b4a7f2f0ad0bbd95f9e8/src/co/deps/ring_etag_middleware.clj#L67C10-L67C29

@danielcompton
Copy link
Member

Great! I'm happy to take a patch for this.

@uvNikita
Copy link

For someone looking at it in the future, I didn't manage to figure out a way with JarURLInputStream to stream file contents and calculate checksum at the same time. Specifically what I was missing is to be able to "reset" JarURLInputStream after it has been consumed for checksum calculation and return it in result.

I ended up calculating checksum of all static files (js,css,images) during the uberjar build process and storing the sums in a separate file in resources. Then this file can be used to compare checksums in production.

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

No branches or pull requests

3 participants