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:
authorHamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com>2023-05-20 17:45:20 +0300
committerHamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com>2023-05-20 17:45:20 +0300
commit4831c2f1b2c73c1e40f23a61e728530b7cf4afe9 (patch)
treeedbc420456de52a9a936e76f99d09ec164e43eb2 /web/network/autp_https_conn.go
parent3166d497f99df530e3a909ab1ba134fe53ef39ff (diff)
Add tgLang option
Diffstat (limited to 'web/network/autp_https_conn.go')
-rw-r--r--web/network/autp_https_conn.go67
1 files changed, 0 insertions, 67 deletions
diff --git a/web/network/autp_https_conn.go b/web/network/autp_https_conn.go
deleted file mode 100644
index d1a9d521..00000000
--- a/web/network/autp_https_conn.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package network
-
-import (
- "bufio"
- "bytes"
- "fmt"
- "net"
- "net/http"
- "sync"
-)
-
-type AutoHttpsConn struct {
- net.Conn
-
- firstBuf []byte
- bufStart int
-
- readRequestOnce sync.Once
-}
-
-func NewAutoHttpsConn(conn net.Conn) net.Conn {
- return &AutoHttpsConn{
- Conn: conn,
- }
-}
-
-func (c *AutoHttpsConn) readRequest() bool {
- c.firstBuf = make([]byte, 2048)
- n, err := c.Conn.Read(c.firstBuf)
- c.firstBuf = c.firstBuf[:n]
- if err != nil {
- return false
- }
- reader := bytes.NewReader(c.firstBuf)
- bufReader := bufio.NewReader(reader)
- request, err := http.ReadRequest(bufReader)
- if err != nil {
- return false
- }
- resp := http.Response{
- Header: http.Header{},
- }
- resp.StatusCode = http.StatusTemporaryRedirect
- location := fmt.Sprintf("https://%v%v", request.Host, request.RequestURI)
- resp.Header.Set("Location", location)
- resp.Write(c.Conn)
- c.Close()
- c.firstBuf = nil
- return true
-}
-
-func (c *AutoHttpsConn) Read(buf []byte) (int, error) {
- c.readRequestOnce.Do(func() {
- c.readRequest()
- })
-
- if c.firstBuf != nil {
- n := copy(buf, c.firstBuf[c.bufStart:])
- c.bufStart += n
- if c.bufStart >= len(c.firstBuf) {
- c.firstBuf = nil
- }
- return n, nil
- }
-
- return c.Conn.Read(buf)
-}