Ensure content-type is explicitly set for WASM files

Johan Brandhorst 2018-08-27 08:56:00 +01:00
parent f43537c729
commit 28eca6e028

@ -41,6 +41,7 @@ import (
"flag"
"log"
"net/http"
"strings"
)
var (
@ -51,7 +52,13 @@ var (
func main() {
flag.Parse()
log.Printf("listening on %q...", *listen)
log.Fatal(http.ListenAndServe(*listen, http.FileServer(http.Dir(*dir))))
log.Fatal(http.ListenAndServe(*listen, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if strings.HasSuffix(req.URL.Path, ".wasm") {
resp.Header().Set("content-type", "application/wasm")
}
http.FileServer(http.Dir(*dir)).ServeHTTP(resp, req)
})))
}
```