summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/daq/s5proxy/sample.json8
-rw-r--r--src/daq/s5proxy/src/s5proxy/config.go54
-rw-r--r--src/daq/s5proxy/src/s5proxy/proxy.go22
3 files changed, 72 insertions, 12 deletions
diff --git a/src/daq/s5proxy/sample.json b/src/daq/s5proxy/sample.json
index 1339fbf..7f5ac66 100644
--- a/src/daq/s5proxy/sample.json
+++ b/src/daq/s5proxy/sample.json
@@ -7,7 +7,9 @@
"X-hello": "world",
"X-verr": "stefan"
},
- "response_header": {
- "Cache-Control": "no-cache"
- }
+ "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" }
+ ]
}
diff --git a/src/daq/s5proxy/src/s5proxy/config.go b/src/daq/s5proxy/src/s5proxy/config.go
index bffb672..ec7e467 100644
--- a/src/daq/s5proxy/src/s5proxy/config.go
+++ b/src/daq/s5proxy/src/s5proxy/config.go
@@ -37,13 +37,60 @@ import (
"os"
)
+type Operation uint
+
+const (
+ OpAdd Operation = iota
+ OpDel
+ OpSet
+)
+
+func (o Operation) String() string {
+ switch o {
+ case OpAdd:
+ return "add"
+ case OpDel:
+ return "del"
+ case OpSet:
+ return "set"
+ }
+ return "unknown"
+}
+
+func (o *Operation) fromString(str string) (err error) {
+ switch str {
+ case "add":
+ *o = OpAdd
+ case "del":
+ *o = OpDel
+ case "set":
+ *o = OpSet
+ }
+ return
+}
+
+func (o Operation) MarshalText() (data []byte, err error) {
+ data = []byte(o.String())
+ return
+}
+
+func (o *Operation) UnmarshalJSON(data []byte) (err error) {
+ return o.fromString(string(data))
+}
+
+type HeaderOperation struct {
+ Header string `json:"header"`
+ Value string `json:"value"`
+ Operation Operation `json:"op"`
+}
+
type Config struct {
ListenAddr string `json:"listen"`
ConnectAddr string `json:"connect"`
CertFile string `json:"cert"`
KeyFile string `json:"key"`
- RequestHeader map[string]string `json:"request_header"`
- ResponseHeader map[string]string `json:"response_header"`
+ RequestHeader []HeaderOperation `json:"request_header"`
+ ResponseHeader []HeaderOperation `json:"response_header"`
}
func readConfig(configfile string) (conf *Config, err error) {
@@ -56,9 +103,6 @@ func readConfig(configfile string) (conf *Config, err error) {
defer f.Close()
conf = &Config{}
- conf.RequestHeader = make(map[string]string)
- conf.ResponseHeader = make(map[string]string)
-
err = json.NewDecoder(f).Decode(conf)
return
}
diff --git a/src/daq/s5proxy/src/s5proxy/proxy.go b/src/daq/s5proxy/src/s5proxy/proxy.go
index d1fb892..282d502 100644
--- a/src/daq/s5proxy/src/s5proxy/proxy.go
+++ b/src/daq/s5proxy/src/s5proxy/proxy.go
@@ -53,8 +53,15 @@ func (r s5proxyResponseWriter) Write(data []byte) (int, error) {
}
func (r s5proxyResponseWriter) WriteHeader(status int) {
- for hdr, value := range r.conf.ResponseHeader {
- r.wrapped.Header().Set(hdr, value)
+ for _, h := range r.conf.ResponseHeader {
+ switch h.Operation {
+ case OpAdd:
+ r.wrapped.Header().Add(h.Header, h.Value)
+ case OpDel:
+ r.wrapped.Header().Del(h.Header)
+ case OpSet:
+ r.wrapped.Header().Set(h.Header, h.Value)
+ }
}
r.wrapped.WriteHeader(status)
}
@@ -74,8 +81,15 @@ func s5proxyInit(conf *Config) (m *http.ServeMux, err error) {
p.Director = func(req *http.Request) {
origDir(req)
- for hdr, value := range conf.RequestHeader {
- req.Header.Set(hdr, value)
+ for _, h := range conf.RequestHeader {
+ switch h.Operation {
+ case OpAdd:
+ req.Header.Add(h.Header, h.Value)
+ case OpDel:
+ req.Header.Del(h.Header)
+ case OpSet:
+ req.Header.Set(h.Header, h.Value)
+ }
}
}