MCPcopy Create free account
hub / github.com/GuyARoss/orbit / setupMuxRequirements

Method setupMuxRequirements

examples/basic-react/orbitgen/orb_http.go:243–270  ·  view source on GitHub ↗

setupMuxRequirements creates the required mux handlers for orbit, these include - fileserver for the bundle directory bound to the "/p/" directory

()

Source from the content-addressed store, hash-verified

241// setupMuxRequirements creates the required mux handlers for orbit, these include
242// - fileserver for the bundle directory bound to the "/p/" directory
243func (s *Serve) setupMuxRequirements() *Serve {
244 pool := sync.Pool{
245 New: func() interface{} {
246 w := gzip.NewWriter(ioutil.Discard)
247 return w
248 },
249 }
250 s.mux.HandleFunc("/p/", func(w http.ResponseWriter, r *http.Request) {
251 // TODO(guy): allow these cache policies to be overwritten
252 switch CurrentDevMode {
253 case DevBundleMode:
254 w.Header().Set("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate")
255 case ProdBundleMode:
256 w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
257 }
258 if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
259 w.Header().Set("Content-Encoding", "gzip")
260 gz := pool.Get().(*gzip.Writer)
261 defer pool.Put(gz)
262 gz.Reset(w)
263 defer gz.Close()
264 http.StripPrefix("/p/", http.FileServer(http.Dir(bundleDir))).ServeHTTP(&gzipResponseWriter{ResponseWriter: w, Writer: gz}, r)
265 return
266 }
267 http.StripPrefix("/p/", http.FileServer(http.Dir(bundleDir))).ServeHTTP(w, r)
268 })
269 return s
270}
271// Serve returns the mux server
272func (s *Serve) Serve() MuxHandler {
273 return s.mux

Callers 3

TestSetupMuxRequirementsFunction · 0.95
NewFunction · 0.45

Calls 7

SetMethod · 0.80
ContainsMethod · 0.80
HandleFuncMethod · 0.65
CloseMethod · 0.65
ServeHTTPMethod · 0.65
HeaderMethod · 0.45
ResetMethod · 0.45

Tested by 2

TestSetupMuxRequirementsFunction · 0.76