-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.go
More file actions
45 lines (42 loc) · 927 Bytes
/
Copy pathserver.go
File metadata and controls
45 lines (42 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package securehttp
import (
"log"
"net/http"
"strconv"
)
type Server struct {
http.Handler
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
t := r.Header.Get("secure-type")
if t == "" {
s.Handler.ServeHTTP(w, r)
return
}
k := r.Header.Get("secure-publickey")
if k == "" {
http.Error(w, "must provide secure-publickey header", http.StatusUnauthorized)
return
}
ms := r.Header.Get("secure-messagesize")
if ms == "" {
http.Error(w, "must provide secure-messagesize header", http.StatusUnauthorized)
return
}
size, e := strconv.Atoi(ms)
if e != nil {
log.Println(e)
http.Error(w, "invalid secure-messagesize header", http.StatusBadRequest)
return
}
w2, e := NewEncryptedWriter(t, k, size, w)
if e != nil {
log.Println(e)
http.Error(w, e.Error(), http.StatusBadRequest)
return
}
w2.Header().Set("secure-type", t)
s.Handler.ServeHTTP(w2, r)
w2.Flush()
return
}