Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsanaei <ho3ein.sanaei@gmail.com>2025-09-20 10:35:50 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2025-09-20 10:35:50 +0300
commit6ced549deaecb42b9bb93ea9efcb4c1bbaabe8a4 (patch)
tree28d8d82530476cf607e4d05ca189ae05868711e6 /web/network
parentf60682a6b7cb749fee403c84e2587c3ad7e7ced0 (diff)
docs: add comments for all functions
Diffstat (limited to 'web/network')
-rw-r--r--web/network/auto_https_conn.go10
-rw-r--r--web/network/auto_https_listener.go6
2 files changed, 16 insertions, 0 deletions
diff --git a/web/network/auto_https_conn.go b/web/network/auto_https_conn.go
index d1a9d521..aa0e9dea 100644
--- a/web/network/auto_https_conn.go
+++ b/web/network/auto_https_conn.go
@@ -1,3 +1,5 @@
+// Package network provides network utilities for the 3x-ui web panel,
+// including automatic HTTP to HTTPS redirection functionality.
package network
import (
@@ -9,6 +11,9 @@ import (
"sync"
)
+// AutoHttpsConn wraps a net.Conn to provide automatic HTTP to HTTPS redirection.
+// It intercepts the first read to detect HTTP requests and responds with a 307 redirect
+// to the HTTPS equivalent URL. Subsequent reads work normally for HTTPS connections.
type AutoHttpsConn struct {
net.Conn
@@ -18,6 +23,8 @@ type AutoHttpsConn struct {
readRequestOnce sync.Once
}
+// NewAutoHttpsConn creates a new AutoHttpsConn that wraps the given connection.
+// It enables automatic redirection of HTTP requests to HTTPS.
func NewAutoHttpsConn(conn net.Conn) net.Conn {
return &AutoHttpsConn{
Conn: conn,
@@ -49,6 +56,9 @@ func (c *AutoHttpsConn) readRequest() bool {
return true
}
+// Read implements the net.Conn Read method with automatic HTTPS redirection.
+// On the first read, it checks if the request is HTTP and redirects to HTTPS if so.
+// Subsequent reads work normally.
func (c *AutoHttpsConn) Read(buf []byte) (int, error) {
c.readRequestOnce.Do(func() {
c.readRequest()
diff --git a/web/network/auto_https_listener.go b/web/network/auto_https_listener.go
index 26614696..32dc307d 100644
--- a/web/network/auto_https_listener.go
+++ b/web/network/auto_https_listener.go
@@ -2,16 +2,22 @@ package network
import "net"
+// AutoHttpsListener wraps a net.Listener to provide automatic HTTPS redirection.
+// It returns AutoHttpsConn connections that handle HTTP to HTTPS redirection.
type AutoHttpsListener struct {
net.Listener
}
+// NewAutoHttpsListener creates a new AutoHttpsListener that wraps the given listener.
+// It enables automatic redirection of HTTP requests to HTTPS for all accepted connections.
func NewAutoHttpsListener(listener net.Listener) net.Listener {
return &AutoHttpsListener{
Listener: listener,
}
}
+// Accept implements the net.Listener Accept method.
+// It accepts connections and wraps them with AutoHttpsConn for HTTPS redirection.
func (l *AutoHttpsListener) Accept() (net.Conn, error) {
conn, err := l.Listener.Accept()
if err != nil {