mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-12 08:34:43 +00:00
Rewrite server to use explicit listener
This commit is contained in:
parent
f38dfbbf78
commit
35d1cedc24
1 changed files with 28 additions and 14 deletions
34
webhook.go
34
webhook.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -168,7 +169,8 @@ func main() {
|
||||||
|
|
||||||
err = watcher.Add(hooksFilePath)
|
err = watcher.Add(hooksFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("error adding hooks file to the watcher\n", err)
|
log.Print("error adding hooks file to the watcher\n", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,25 +198,37 @@ func main() {
|
||||||
|
|
||||||
r.HandleFunc(hooksURL, hookHandler)
|
r.HandleFunc(hooksURL, hookHandler)
|
||||||
|
|
||||||
if !*secure {
|
// Create common HTTP server settings
|
||||||
log.Printf("serving hooks on http://%s:%d%s", *ip, *port, hooksURL)
|
|
||||||
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", *ip, *port), r))
|
|
||||||
}
|
|
||||||
|
|
||||||
svr := &http.Server{
|
svr := &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", *ip, *port),
|
Addr: fmt.Sprintf("%s:%d", *ip, *port),
|
||||||
Handler: r,
|
Handler: r,
|
||||||
TLSConfig: &tls.Config{
|
}
|
||||||
|
|
||||||
|
// Open listener
|
||||||
|
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", *ip, *port))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error listening on port: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serve HTTP
|
||||||
|
if !*secure {
|
||||||
|
log.Printf("serving hooks on http://%s:%d%s", *ip, *port, hooksURL)
|
||||||
|
log.Print(svr.Serve(ln))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server HTTPS
|
||||||
|
svr.TLSConfig = &tls.Config{
|
||||||
CipherSuites: getTLSCipherSuites(*tlsCipherSuites),
|
CipherSuites: getTLSCipherSuites(*tlsCipherSuites),
|
||||||
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
|
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
|
||||||
MinVersion: getTLSMinVersion(*tlsMinVersion),
|
MinVersion: getTLSMinVersion(*tlsMinVersion),
|
||||||
PreferServerCipherSuites: true,
|
PreferServerCipherSuites: true,
|
||||||
},
|
|
||||||
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)), // disable http/2
|
|
||||||
}
|
}
|
||||||
|
svr.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler)) // disable http/2
|
||||||
|
|
||||||
log.Printf("serving hooks on https://%s:%d%s", *ip, *port, hooksURL)
|
log.Printf("serving hooks on https://%s:%d%s", *ip, *port, hooksURL)
|
||||||
log.Fatal(svr.ListenAndServeTLS(*cert, *key))
|
log.Print(svr.ServeTLS(ln, *cert, *key))
|
||||||
}
|
}
|
||||||
|
|
||||||
func hookHandler(w http.ResponseWriter, r *http.Request) {
|
func hookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue