/
bucket.go
30 lines (28 loc) · 963 Bytes
/
bucket.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
package router
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
func (r *Router) HandleBucketAsset(path string, writer http.ResponseWriter, request *http.Request) {
contentType := "application/octet-stream"
if strings.HasSuffix(path, ".js") {
contentType = "application/javascript"
} else if strings.HasSuffix(path, ".ico") {
contentType = "image/x-icon"
} else if strings.HasSuffix(path, ".gif") {
contentType = "image/gif"
} else if strings.HasSuffix(path, ".svg") {
contentType = "image/svg+xml"
} else if strings.HasSuffix(path, ".pdf") {
contentType = "application/pdf"
}
writer.Header().Set("Content-Type", contentType)
writer.Header().Set("Connection", "keep-alive")
writer.Header().Set("Cache-Control", "max-age=3600, public, must-revalidate, proxy-revalidate")
path = path[7:]
asBytes, _ := ioutil.ReadFile(r.BucketPath + path)
writer.Header().Set("Content-Length", fmt.Sprintf("%d", len(asBytes)))
writer.Write(asBytes)
}