summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/daq/s5proxy/sample.json4
-rw-r--r--src/daq/s5proxy/src/s5proxy/config.go5
-rw-r--r--src/daq/s5proxy/src/s5proxy/proxy.go19
3 files changed, 27 insertions, 1 deletions
diff --git a/src/daq/s5proxy/sample.json b/src/daq/s5proxy/sample.json
index 92737fa..65dc768 100644
--- a/src/daq/s5proxy/sample.json
+++ b/src/daq/s5proxy/sample.json
@@ -9,6 +9,8 @@
"response_header": [
{ "op": "set", "header": "Cache-Control", "value": "no-cache" },
{ "op": "add", "header": "Cache-Control", "value": "no-store" },
- { "op": "add", "header": "Cache-Control", "value": "must-revalidate" }
+ { "op": "add", "header": "Cache-Control", "value": "must-revalidate" },
+ { "op": "add", "header": "Cache-Control", "value": "max-age=0" },
+ { "op": "time", "header": "Expires", "value": "-1s" }
]
}
diff --git a/src/daq/s5proxy/src/s5proxy/config.go b/src/daq/s5proxy/src/s5proxy/config.go
index 09fad61..c61a152 100644
--- a/src/daq/s5proxy/src/s5proxy/config.go
+++ b/src/daq/s5proxy/src/s5proxy/config.go
@@ -44,6 +44,7 @@ const (
OpAdd Operation = iota
OpDel
OpSet
+ OpTime
)
func (o Operation) String() string {
@@ -54,6 +55,8 @@ func (o Operation) String() string {
return "del"
case OpSet:
return "set"
+ case OpTime:
+ return "time"
}
return "unknown"
}
@@ -66,6 +69,8 @@ func (o *Operation) fromString(str string) (err error) {
*o = OpDel
case "set":
*o = OpSet
+ case "time":
+ *o = OpTime
default:
return errors.New("invalid operation: '" + str + "'")
}
diff --git a/src/daq/s5proxy/src/s5proxy/proxy.go b/src/daq/s5proxy/src/s5proxy/proxy.go
index 09b6bd5..33cbc14 100644
--- a/src/daq/s5proxy/src/s5proxy/proxy.go
+++ b/src/daq/s5proxy/src/s5proxy/proxy.go
@@ -37,8 +37,19 @@ import (
"net/http"
"net/http/httputil"
"net/url"
+ "time"
)
+func generateTime(input string) string {
+ d, err := time.ParseDuration(input)
+ if err != nil {
+ s5l.Printf("can't parse duration: %v", err)
+ return ""
+ }
+
+ return time.Now().Add(d).Format(time.RFC1123)
+}
+
type s5proxyResponseWriter struct {
wrapped http.ResponseWriter
conf *Config
@@ -61,6 +72,10 @@ func (r s5proxyResponseWriter) WriteHeader(status int) {
r.wrapped.Header().Del(h.Header)
case OpSet:
r.wrapped.Header().Set(h.Header, h.Value)
+ case OpTime:
+ if ts := generateTime(h.Value); ts != "" {
+ r.wrapped.Header().Set(h.Header, ts)
+ }
}
}
r.wrapped.WriteHeader(status)
@@ -100,6 +115,10 @@ func NewProxy(conf *Config) (p *Proxy, err error) {
req.Header.Del(h.Header)
case OpSet:
req.Header.Set(h.Header, h.Value)
+ case OpTime:
+ if ts := generateTime(h.Value); ts != "" {
+ req.Header.Set(h.Header, ts)
+ }
}
}
}