The code and data behind xeiaso.net
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/lume: start work on dynamically replacing the zip filesystem for XeDN serving

Signed-off-by: Xe Iaso <me@xeiaso.net>

Xe Iaso 88ce81cc 93070819

+76 -1
+1
go.mod
··· 21 21 github.com/acomagu/bufpipe v1.0.4 // indirect 22 22 github.com/akutz/memconn v0.1.0 // indirect 23 23 github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect 24 + github.com/andybalholm/brotli v1.0.6 // indirect 24 25 github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect 25 26 github.com/aws/aws-sdk-go-v2/config v1.18.22 // indirect 26 27 github.com/aws/aws-sdk-go-v2/credentials v1.13.21 // indirect
+2
go.sum
··· 17 17 github.com/akutz/memconn v0.1.0/go.mod h1:Jo8rI7m0NieZyLI5e2CDlRdRqRRB4S7Xp77ukDjH+Fw= 18 18 github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 h1:Kk6a4nehpJ3UuJRqlA3JxYxBZEqCeOmATOvrbT4p9RA= 19 19 github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4= 20 + github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI= 21 + github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= 20 22 github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= 21 23 github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= 22 24 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
+22
internal/headerparams.go
··· 1 + package internal 2 + 3 + import ( 4 + "strings" 5 + ) 6 + 7 + func ParseValueAndParams(value string) map[string]string { 8 + parts := strings.Split(value, ",") 9 + vals := make(map[string]string) 10 + 11 + for _, part := range parts { 12 + part = strings.TrimSpace(part) 13 + if part == "" { 14 + continue 15 + } 16 + 17 + parts := strings.Split(part, ";") 18 + vals[parts[0]] = strings.Join(parts[1:], ";") 19 + } 20 + 21 + return vals 22 + }
+51 -1
internal/lume/zip.go
··· 10 10 "os" 11 11 "path/filepath" 12 12 "strings" 13 + "sync" 14 + 15 + "xeiaso.net/v4/internal" 13 16 ) 14 17 15 - const compressionGZIP = 0x69 18 + const ( 19 + compressionGZIP = 0x69 20 + ) 16 21 17 22 func init() { 18 23 zip.RegisterCompressor(compressionGZIP, func(w io.Writer) (io.WriteCloser, error) { ··· 163 168 // The file is compressible by both its header and name 164 169 return true, nil 165 170 } 171 + 172 + type ZipServer struct { 173 + lock sync.RWMutex 174 + zip *zip.ReadCloser 175 + } 176 + 177 + func NewZipServer(zipPath string) (*ZipServer, error) { 178 + file, err := zip.OpenReader(zipPath) 179 + if err != nil { 180 + return nil, err 181 + } 182 + 183 + result := &ZipServer{ 184 + zip: file, 185 + } 186 + 187 + return result, nil 188 + } 189 + 190 + func (zs *ZipServer) Update(fname string) error { 191 + zs.lock.Lock() 192 + defer zs.lock.Unlock() 193 + 194 + old := zs.zip 195 + 196 + file, err := zip.OpenReader(fname) 197 + if err != nil { 198 + return err 199 + } 200 + 201 + zs.zip = file 202 + 203 + old.Close() 204 + return nil 205 + } 206 + 207 + func (zs *ZipServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { 208 + zs.lock.RLock() 209 + defer zs.lock.RUnlock() 210 + 211 + vals := internal.ParseValueAndParams(r.Header.Get("Accept-Encoding")) 212 + slog.Info("accept-encoding", "vals", vals) 213 + 214 + http.FileServer(http.FS(zs.zip)).ServeHTTP(w, r) 215 + }