mirror of
https://github.com/adnanh/webhook.git
synced 2025-10-04 13:41:03 +00:00
Add PROXY protocol support
This commit adds a custom net.Listener to the webhook HTTP server to enable PROXY protocol support. I've copied in the keep-alive listener from the Go net/http package, so the non-PROXY server should behave just like the stdlib.
This commit is contained in:
parent
df781925f1
commit
d1788369dd
2 changed files with 55 additions and 4 deletions
30
http.go
Normal file
30
http.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// tcpKeepAliveListener copied from Go net/http package.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
|
||||
// connections. It's used by ListenAndServe and ListenAndServeTLS so
|
||||
// dead TCP connections (e.g. closing laptop mid-download) eventually
|
||||
// go away.
|
||||
type tcpKeepAliveListener struct {
|
||||
*net.TCPListener
|
||||
}
|
||||
|
||||
func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
|
||||
tc, err := ln.AcceptTCP()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tc.SetKeepAlive(true)
|
||||
tc.SetKeepAlivePeriod(3 * time.Minute)
|
||||
return tc, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue