Support SNI routing with Postgres STARTTLS connections

Co-authored-by: Michael Kuhnt <michael.kuhnt@daimler.com>
Co-authored-by: Julien Salleyron <julien@containo.us>
Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
Romain 2022-11-16 15:34:10 +01:00 committed by GitHub
parent fadee5e87b
commit 630de7481e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 295 additions and 13 deletions

View file

@ -108,6 +108,17 @@ func (r *Router) ServeTCP(conn tcp.WriteCloser) {
// TODO -- Check if ProxyProtocol changes the first bytes of the request
br := bufio.NewReader(conn)
postgres, err := isPostgres(br)
if err != nil {
conn.Close()
return
}
if postgres {
r.servePostgres(r.GetConn(conn, getPeeked(br)))
return
}
hello, err := clientHelloInfo(br)
if err != nil {
conn.Close()
@ -277,7 +288,7 @@ func (r *Router) SetHTTPSHandler(handler http.Handler, config *tls.Config) {
type Conn struct {
// Peeked are the bytes that have been read from Conn for the
// purposes of route matching, but have not yet been consumed
// by Read calls. It set to nil by Read when fully consumed.
// by Read calls. It is set to nil by Read when fully consumed.
Peeked []byte
// Conn is the underlying connection.