Skip to content

Commit

Permalink
Add header selection for a version
Browse files Browse the repository at this point in the history
  • Loading branch information
biangeevibegx authored and brendandburns committed Aug 25, 2023
1 parent 04a0c49 commit 4428905
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ func (w *WebAssembly) Provision(ctx caddy.Context) error {
}

func (w *WebAssembly) ServeHTTP(res http.ResponseWriter, req *http.Request, next caddyhttp.Handler) error {
instance, err := w.loader.GetOrLoad(req.Context(), w.defaultVersion)
version := req.Header.Get("x-caddy-wasm-version")
if len(version) == 0 {
version = w.defaultVersion
}
instance, err := w.loader.GetOrLoad(req.Context(), version)
if instance == nil {
res.WriteHeader(http.StatusInternalServerError)
res.Write([]byte("Failed to load wasm: " + err.Error()))
Expand Down

0 comments on commit 4428905

Please sign in to comment.