diff --git a/cmd/proxy/main.go b/cmd/proxy/main.go index 33d451f..db75c9d 100644 --- a/cmd/proxy/main.go +++ b/cmd/proxy/main.go @@ -55,9 +55,9 @@ func configFromFile(path string) (*cacheproxy.Config, error) { Local: &cacheproxy.LocalStorage{ Path: "./data", TemporaryFilePattern: "temp.*", - }, - Accel: cacheproxy.Accel{ - ResponseWithHeaders: []string{"X-Sendfile", "X-Accel-Redirect"}, + Accel: cacheproxy.Accel{ + RespondWithHeaders: []string{"X-Sendfile", "X-Accel-Redirect"}, + }, }, }, Misc: cacheproxy.MiscConfig{ diff --git a/config.go b/config.go index c6092de..e9999fc 100644 --- a/config.go +++ b/config.go @@ -36,17 +36,18 @@ func (upstream Upstream) GetPath(orig string) (string, bool, error) { type LocalStorage struct { Path string `yaml:"path"` TemporaryFilePattern string `yaml:"temporary-file-pattern"` + + Accel Accel `yaml:"accel"` } type Accel struct { - EnableByHeader string `yaml:"enable-by-header"` - ResponseWithHeaders []string `yaml:"response-with-headers"` + EnableByHeader string `yaml:"enable-by-header"` + RespondWithHeaders []string `yaml:"respond-with-headers"` } type Storage struct { Type string `yaml:"type"` Local *LocalStorage `yaml:"local"` - Accel Accel `yaml:"accel"` } type CachePolicyOnPath struct { diff --git a/config.yaml b/config.yaml index c940135..4372558 100644 --- a/config.yaml +++ b/config.yaml @@ -88,21 +88,21 @@ upstream: allowed-redirect: "^https?://cf-builds.garudalinux.org/.*/chaotic-aur/.*$" misc: - first-chunk-bytes: 31457280 # 1024*1024*30, all upstreams with 200 response will wait for the first chunks to select a upstream by bandwidth, instead of by latency. defaults to 50M - # chunk-bytes: 1048576 # 1024*1024 + first-chunk-bytes: 31457280 ## 1024*1024*30, all upstreams with 200 response will wait for the first chunks to select a upstream by bandwidth, instead of by latency. defaults to 50M + # chunk-bytes: 1048576 ## 1024*1024 cache: timeout: 1h policies: - - match: '.*\.(rpm|deb|apk|iso)$' # rpm/deb/apk/iso won't change, create only + - match: '.*\.(rpm|deb|apk|iso)$' ## rpm/deb/apk/iso won't change, create only refresh-after: never - - match: '^/.*-security/.*' # mostly ubuntu/debian security + - match: '^/.*-security/.*' ## mostly ubuntu/debian security refresh-after: 1h - - match: '^/archlinux-localaur/.*' # archlinux local repo + - match: '^/archlinux-localaur/.*' ## archlinux local repo refresh-after: never - - match: '^/(archlinux.*|chaotic-aur)/*.tar.*' # archlinux packages + - match: '^/(archlinux.*|chaotic-aur)/*.tar.*' ## archlinux packages refresh-after: never - - match: '/chaotic-aur/.*\.db$' # archlinux chaotic-aur database + - match: '/chaotic-aur/.*\.db$' ## archlinux chaotic-aur database refresh-after: 24h - match: '/centos/7' refresh-after: never @@ -110,20 +110,23 @@ cache: refresh-after: never storage: - type: local # ignored + type: local ## ignored for now local: - path: ./data # defaults to ./data + path: ./data ## defaults to ./data - accel: - # example nginx config: - ## location /i { - ## internal; - ## alias /path/to/data; - ## } - ## location / { - ## proxy_pass 127.0.0.1:8881; - ## proxy_set_header X-Accel-Path /i; - ## } - ## + accel: + ## example nginx config: + ## location /i { + ## internal; + ## alias /path/to/data; + ## } + ## location / { + ## proxy_pass 127.0.0.1:8881; + ## proxy_set_header X-Accel-Path /i; + ## } + ## + ## then cache proxy will respond to backend a header to indicate sendfile(join(X-Accel-Path, relpath)) + # enable-by-header: "X-Accel-Path" - # enable-by-header: "X-Accel-Path" + ## respond with different headers to + # respond-with-headers: [X-Sendfile, X-Accel-Redirect] diff --git a/server.go b/server.go index bb5e249..fbf1e17 100644 --- a/server.go +++ b/server.go @@ -107,7 +107,7 @@ type Chunk struct { } func (server *Server) serveFile(w http.ResponseWriter, r *http.Request, path string) { - if location := r.Header.Get(server.Storage.Accel.EnableByHeader); server.Storage.Accel.EnableByHeader != "" && location != "" { + if location := r.Header.Get(server.Storage.Local.Accel.EnableByHeader); server.Storage.Local.Accel.EnableByHeader != "" && location != "" { relPath, err := filepath.Rel(server.Storage.Local.Path, path) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) @@ -115,7 +115,7 @@ func (server *Server) serveFile(w http.ResponseWriter, r *http.Request, path str } accelPath := filepath.Join(location, relPath) - for _, headerKey := range server.Storage.Accel.ResponseWithHeaders { + for _, headerKey := range server.Storage.Local.Accel.RespondWithHeaders { w.Header().Set(headerKey, accelPath) }