MCPcopy
hub / github.com/nirui/sshwifty / serveStaticPage

Function serveStaticPage

application/controller/static.go:51–83  ·  view source on GitHub ↗
(
	dataName string,
	w http.ResponseWriter,
	r *http.Request,
	l log.Logger,
)

Source from the content-addressed store, hash-verified

49}
50
51func serveStaticPage(
52 dataName string,
53 w http.ResponseWriter,
54 r *http.Request,
55 l log.Logger,
56) error {
57 d, dFound := staticPages[dataName]
58
59 if !dFound {
60 return ErrNotFound
61 }
62
63 selectedData := d.data
64
65 if clientSupportGZIP(r) && d.hasCompressed() {
66 selectedData = d.compressd
67
68 w.Header().Add("Vary", "Accept-Encoding")
69 w.Header().Add("Content-Encoding", "gzip")
70 }
71
72 mimeType := mime.TypeByExtension(staticFileExt(dataName))
73
74 if len(mimeType) > 0 {
75 w.Header().Add("Content-Type", mimeType)
76 } else {
77 w.Header().Add("Content-Type", "application/binary")
78 }
79
80 _, wErr := w.Write(selectedData)
81
82 return wErr
83}
84
85func serveStaticData(
86 dataName string,

Callers 2

serveFailureFunction · 0.85
GetMethod · 0.85

Calls 4

clientSupportGZIPFunction · 0.85
staticFileExtFunction · 0.85
hasCompressedMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected