This commit is contained in:
@ -299,6 +299,7 @@ func Handler(conn net.Conn) {
|
|||||||
dstReader := bufio.NewReader(conn)
|
dstReader := bufio.NewReader(conn)
|
||||||
reqhf, err := NewRequestHeaderFactory(dstReader)
|
reqhf, err := NewRequestHeaderFactory(dstReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error creating request header: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,12 +7,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
"tunnel_pls/session"
|
"tunnel_pls/session"
|
||||||
"tunnel_pls/utils"
|
"tunnel_pls/utils"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewHTTPSServer() error {
|
func NewHTTPSServer() error {
|
||||||
@ -57,17 +54,9 @@ func HandlerTLS(conn net.Conn) {
|
|||||||
dstReader := bufio.NewReader(conn)
|
dstReader := bufio.NewReader(conn)
|
||||||
reqhf, err := NewRequestHeaderFactory(dstReader)
|
reqhf, err := NewRequestHeaderFactory(dstReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error creating request header: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cw := NewCustomWriter(conn, dstReader, conn.RemoteAddr())
|
|
||||||
|
|
||||||
// Initial Requests
|
|
||||||
cw.Requests = append(cw.Requests, &RequestContext{
|
|
||||||
Host: reqhf.Get("Host"),
|
|
||||||
Path: reqhf.Path,
|
|
||||||
Method: reqhf.Method,
|
|
||||||
Chunked: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
host := strings.Split(reqhf.Get("Host"), ".")
|
host := strings.Split(reqhf.Get("Host"), ".")
|
||||||
if len(host) < 1 {
|
if len(host) < 1 {
|
||||||
@ -87,34 +76,18 @@ func HandlerTLS(conn net.Conn) {
|
|||||||
slug := host[0]
|
slug := host[0]
|
||||||
|
|
||||||
if slug == "ping" {
|
if slug == "ping" {
|
||||||
req, err := http.ReadRequest(dstReader)
|
// TODO: implement cors
|
||||||
|
_, err := conn.Write([]byte(
|
||||||
|
"HTTP/1.1 200 OK\r\n" +
|
||||||
|
"Content-Length: 0\r\n" +
|
||||||
|
"Connection: close\r\n" +
|
||||||
|
"Access-Control-Allow-Origin: *\r\n" +
|
||||||
|
"Access-Control-Allow-Methods: GET, HEAD, OPTIONS\r\n" +
|
||||||
|
"Access-Control-Allow-Headers: *\r\n" +
|
||||||
|
"\r\n",
|
||||||
|
))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to parse HTTP request:", err)
|
log.Println("Failed to write 200 OK:", err)
|
||||||
return
|
|
||||||
}
|
|
||||||
rw := &connResponseWriter{conn: conn}
|
|
||||||
|
|
||||||
wsConn, err := upgrader.Upgrade(rw, req, nil)
|
|
||||||
if err != nil {
|
|
||||||
if !strings.Contains(err.Error(), "the client is not using the websocket protocol") {
|
|
||||||
log.Println("Upgrade failed:", err)
|
|
||||||
}
|
|
||||||
err := conn.Close()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("failed to close connection:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = wsConn.WriteMessage(websocket.TextMessage, []byte("pong"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println("failed to write pong:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = wsConn.Close()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("websocket close failed :", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -138,6 +111,15 @@ func HandlerTLS(conn net.Conn) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
cw := NewCustomWriter(conn, dstReader, conn.RemoteAddr())
|
||||||
|
|
||||||
|
// Initial Requests
|
||||||
|
cw.Requests = append(cw.Requests, &RequestContext{
|
||||||
|
Host: reqhf.Get("Host"),
|
||||||
|
Path: reqhf.Path,
|
||||||
|
Method: reqhf.Method,
|
||||||
|
Chunked: false,
|
||||||
|
})
|
||||||
forwardRequest(cw, reqhf, sshSession)
|
forwardRequest(cw, reqhf, sshSession)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user