package main
import (
"context"
"fmt"
"io"
"strings"
"github.com/fastly/compute-sdk-go/fsthttp"
)
const Backend = "origin_0"
var HeaderFilters = []string{
"Fastly-Debug-",
"Server",
"Via",
"X-AMZ-",
"X-Generator",
"X-Github-",
"X-Goog-",
}
func main() {
fsthttp.ServeFunc(func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) {
resp, err := r.Send(ctx, Backend)
if err != nil {
w.WriteHeader(fsthttp.StatusBadGateway)
fmt.Fprintln(w, err)
return
}
for _, h := range resp.Header.Keys() {
for _, f := range HeaderFilters {
if strings.HasPrefix(h, f) {
fmt.Println("Delete:", h)
resp.Header.Del(h)
}
}
}
w.Header().Reset(resp.Header)
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
})
}