-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle.go
59 lines (46 loc) · 1.06 KB
/
handle.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"crypto/hmac"
"crypto/sha1"
"fmt"
"github.com/gorilla/mux"
"io"
"log"
"net/http"
"net/url"
)
func digestHandler(w http.ResponseWriter, req *http.Request) {
path := mux.Vars(req)
query, err := url.ParseQuery(req.URL.RawQuery)
if err != nil {
log.Fatal(err.Error())
}
if path["digest"] != "" && query["url"][0] != "" {
destUrl, err := url.QueryUnescape(query["url"][0])
if err != nil {
log.Fatal(err.Error())
}
hmc := hmac.New(sha1.New, []byte(env.SharedKey))
io.WriteString(hmc, destUrl)
sum := fmt.Sprintf("%x", hmc.Sum(nil))
if path["digest"] == sum {
destUrl, err := url.Parse(destUrl)
if err != nil {
log.Fatal(err.Error())
}
proxyImageRequest(&w, destUrl, env.MaxRedirect)
} else {
w.WriteHeader(404)
io.WriteString(w, "not found")
}
} else {
w.WriteHeader(404)
io.WriteString(w, "not found")
}
}
func indexHandler(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, "pong")
}
func statusHandler(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, "status called")
}