Add ETag hash to tunnel responses

This commit is contained in:
Anders Pitman 2020-10-10 08:20:17 -06:00
parent eaddc4441a
commit 41bd4759eb

8
api.go
View File

@ -1,7 +1,9 @@
package main package main
import ( import (
"crypto/md5"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
) )
@ -52,6 +54,12 @@ func (a *Api) handleTunnels(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Error encoding tunnels")) w.Write([]byte("Error encoding tunnels"))
return return
} }
hash := md5.Sum(body)
hashStr := fmt.Sprintf("%x", hash)
w.Header()["ETag"] = []string{hashStr}
w.Write([]byte(body)) w.Write([]byte(body))
case "POST": case "POST":
a.validateSession(http.HandlerFunc(a.handleCreateTunnel)).ServeHTTP(w, r) a.validateSession(http.HandlerFunc(a.handleCreateTunnel)).ServeHTTP(w, r)