hashfs
Implementation of io/fs.FS that appends SHA256 hashes to filenames to allow for aggressive HTTP caching.
For example, given a file path of /scripts/main.js
, the hashfs.FS
filesystem will provide the server with a hashname of /scripts/main-b633a..d628.js
. Note the hash is truncated for brevity. When this file path is requested by the client, the server can verify the hash and return the contents with an aggressive Cache-Control
header. The client will cache this file for up to a year and does not need to re-reqeust it in the future.
Note that this library requires Go 1.16 or higher.
Usage
To use hashfs
, first wrap your embed.FS
in a hashfs.FS
filesystem:
//go:embed scripts stylesheets images
var embedFS embed.FS
var fsys = hashfs.NewFS(embedFS)
Then attach a hashfs.FileServer()
to your router:
http.Handle("/assets", http.StripPrefix("/assets", hashfs.FileServer(fsys)))
Next, your html templating library can obtain the hashname of your file using the hashfs.FS.HashName()
method:
func renderHTML(w io.Writer) {
fmt.Fprintf(w, ``)
fmt.Fprintf(w, `
You might also like...
Coraza Server is the most ambitious implementation of Coraza WAF
Coraza Server is the most ambitious implementation of Coraza WAF, it's designed to integrate with systems written in different languages, like C, using multiple protocols like SPOA, REST and GRPC.
Exploratory implementation of the Eva virtual machine
Eva Exploratory implementation of the Eva virtual machine in pure Go. Eva is a simple virtual machine designed for educational use. This is not intend
Golang implementation of ECVRF-EDWARDS25519-SHA512-TAI, a verifiable random function described in draft-irtf-cfrg-vrf-10.
Go-ECVRF Go-ECVRF is a library that implements ECVRF-EDWARDS25519-SHA512-TAI, a verifiable random function described in draft-irtf-cfrg-vrf-10. By des
This repo contains golang implementation of common DSA problems
DSA This repo contains golang implementation of common DSA problems Trees Tree T
Netcup provider implementation for libdns
netcup for libdns This package implements the libdns interfaces for the netcup DNS API, allowing you to manage DNS records. Configuration The provider
Kerberoasting attack implementation in Golang using go-ldap and gokrb5
Goberoast Kerberoasting attack implementation in Golang using go-ldap and gokrb5. Build You can build the project by simply typing go build within the
A pure-Go implementation of the CVE-2021-4034 PwnKit exploit
go-PwnKit A pure-Go implementation of the CVE-2021-4034 PwnKit exploit. Installation git clone [email protected]:OXDBXKXO/go-PwnKit.git
cd go-PwnKit
make
HTTP middleware for Go that facilitates some quick security wins.
Secure Secure is an HTTP middleware for Go that facilitates some quick security wins. It's a standard net/http Handler, and can be used with many fram
HTTP/HTTPS MITM proxy and recorder.
Hyperfox Hyperfox is a security auditing tool that proxies and records HTTP and HTTPS traffic between two points. Installation You can install the lat
Comments
-
Use http.ServeContent + add ETag header
- Use http.ServeContent instead of io.Copy
http.ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of http.ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.
https://pkg.go.dev/net/http#ServeContent
- Add ETag header
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
opened by SlIdE42 2
Releases(v0.2.1)
-
v0.2.1(Dec 21, 2021)
What's Changed
- Fix missing hash bug + prevent useless RegEx call by @SlIdE42 in https://github.com/benbjohnson/hashfs/pull/3
Full Changelog: https://github.com/benbjohnson/hashfs/compare/v0.2.0...v0.2.1
Source code(tar.gz)
Source code(zip)
-
v0.2.0(Dec 9, 2021)
What's Changed
- Fix typo by @jeffwidman in https://github.com/benbjohnson/hashfs/pull/1
- Use http.ServeContent + add ETag header by @SlIdE42 in https://github.com/benbjohnson/hashfs/pull/2
New Contributors
- @jeffwidman made their first contribution in https://github.com/benbjohnson/hashfs/pull/1
- @SlIdE42 made their first contribution in https://github.com/benbjohnson/hashfs/pull/2
Full Changelog: https://github.com/benbjohnson/hashfs/compare/v0.1.0...v0.2.0
Source code(tar.gz)
Source code(zip)
-
v0.1.0(Dec 11, 2020)
This release includes basic hashing & file serving functionality.
Source code(tar.gz)
Source code(zip)
A convenience library for generating, comparing and inspecting password hashes using the scrypt KDF in Go 🔑
simple-scrypt simple-scrypt provides a convenience wrapper around Go's existing scrypt package that makes it easier to securely derive strong keys ("h
Serpscan is a powerfull php script designed to allow you to leverage the power of dorking straight from the comfort of your command line.
SerpScan Serpscan is a powerful PHP tool designed to allow you to leverage the power of dorking straight from the comfort of your command line. Table
CVE-2021-4034 - A Golang implementation of clubby789's implementation of CVE-2021-4034
CVE-2021-4034 January 25, 2022 | An00bRektn This is a golang implementation of C
Pure Go implementation of the NaCL set of API's
go-nacl This is a pure Go implementation of the API's available in NaCL: https://nacl.cr.yp.to. Compared with the implementation in golang.org/x/crypt
A Go language implementation of the proposed ads.cert protocols for integration in programmatic ads solutions.
go-adscert A Go language implementation of the proposed ads.cert protocols for integration in programmatic ads solutions. This repository is a work-in
PHP functions implementation to Golang. This package is for the Go beginners who have developed PHP code before. You can use PHP like functions in your app, module etc. when you add this module to your project.
PHP Functions for Golang - phpfuncs PHP functions implementation to Golang. This package is for the Go beginners who have developed PHP code before. Y
Consistent hashing hashring implementation.
hashring Consistent hashing hashring implementation. Overview This is an implementation of the consistent hashing hashring data structure. In general,
Implementation of Secret Service API
Secret Service Implementation of Secret Service API What does this project do? By using secret service, you don't need to use KeePassXC secretservice
Implementation of polynomial KZG proofs and 257-ary verkle trie
257-ary verkle trie Disclaimer: the code in this package is experimental. It can only be used in research and is not suitable for use in production. T
Shellcode implementation of Reflective DLL Injection by Golang. Convert DLLs to position independent shellcode
?? Frog For Automatic Scan ?? Doge For Defense Evasion&Offensive Security Doge-sRDI Shellcode implementation of Reflective DLL Injection by Golang. Co