mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-09-19 10:39:40 +02:00
Enable SNI offload in HTTPS proxy connections
Updated the ReverseProxy's ProxyHTTPS method to use tls.Dial with SNI support when connecting to upstream servers. Also incremented SYSTEM_VERSION to 3.2.7.
This commit is contained in:
@@ -44,7 +44,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
/* Build Constants */
|
/* Build Constants */
|
||||||
SYSTEM_NAME = "Zoraxy"
|
SYSTEM_NAME = "Zoraxy"
|
||||||
SYSTEM_VERSION = "3.2.6"
|
SYSTEM_VERSION = "3.2.7"
|
||||||
DEVELOPMENT_BUILD = false
|
DEVELOPMENT_BUILD = false
|
||||||
|
|
||||||
/* System Constants */
|
/* System Constants */
|
||||||
|
@@ -2,10 +2,10 @@ package dpcore
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -391,7 +391,6 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request, rrr
|
|||||||
|
|
||||||
return res.StatusCode, nil
|
return res.StatusCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReverseProxy) ProxyHTTPS(rw http.ResponseWriter, req *http.Request) (int, error) {
|
func (p *ReverseProxy) ProxyHTTPS(rw http.ResponseWriter, req *http.Request) (int, error) {
|
||||||
hij, ok := rw.(http.Hijacker)
|
hij, ok := rw.(http.Hijacker)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -407,12 +406,23 @@ func (p *ReverseProxy) ProxyHTTPS(rw http.ResponseWriter, req *http.Request) (in
|
|||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyConn, err := net.Dial("tcp", req.URL.Host)
|
// Extract SNI/hostname for TLS handshake
|
||||||
|
host := req.URL.Host
|
||||||
|
if !strings.Contains(host, ":") {
|
||||||
|
host += ":443"
|
||||||
|
}
|
||||||
|
serverName := req.URL.Hostname()
|
||||||
|
|
||||||
|
// Connect with SNI offload
|
||||||
|
tlsConfig := &tls.Config{
|
||||||
|
ServerName: serverName,
|
||||||
|
}
|
||||||
|
proxyConn, err := tls.Dial("tcp", host, tlsConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if p.Verbal {
|
if p.Verbal {
|
||||||
p.logf("http: proxy error: %v", err)
|
p.logf("http: proxy error: %v", err)
|
||||||
}
|
}
|
||||||
|
clientConn.Close()
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user