Add HTTP2 config option for policy plugin (#16225)

This commit is contained in:
Aditya Manthramurthy
2022-12-13 14:28:48 -08:00
committed by GitHub
parent 709eb283d9
commit 9e6cc847f8
8 changed files with 87 additions and 23 deletions

View File

@@ -22,6 +22,7 @@ package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"log"
@@ -29,6 +30,16 @@ import (
"strings"
)
var (
keyFile string
certFile string
)
func init() {
flag.StringVar(&keyFile, "key-file", "", "Path to TLS cert key file")
flag.StringVar(&certFile, "cert-file", "", "Path to TLS cert file")
}
func writeErrorResponse(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(map[string]string{
@@ -77,8 +88,22 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
}
func main() {
flag.Parse()
serveFunc := func() error {
return http.ListenAndServe(":8080", nil)
}
if certFile != "" || keyFile != "" {
if certFile == "" || keyFile == "" {
log.Fatal("Please provide both a key file and a cert file to enable TLS.")
}
serveFunc = func() error {
return http.ListenAndServeTLS(":8080", certFile, keyFile, nil)
}
}
http.HandleFunc("/", mainHandler)
log.Print("Listening on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
log.Fatal(serveFunc())
}