@@ -3,8 +3,6 @@ package http_proxy
3
3
import (
4
4
"context"
5
5
"errors"
6
- "io"
7
- "net"
8
6
"net/http"
9
7
"net/http/httputil"
10
8
"os"
@@ -23,53 +21,6 @@ func logRequest(next http.HandlerFunc) http.HandlerFunc {
23
21
}
24
22
}
25
23
26
- func tunnel (w http.ResponseWriter , r * http.Request ) {
27
- dialer := net.Dialer {}
28
- serverConn , err := dialer .DialContext (r .Context (), "tcp" , r .Host )
29
- if err != nil {
30
- log .Error ("failed to connect to upstream %s" , r .Host )
31
- http .Error (w , http .StatusText (http .StatusServiceUnavailable ), http .StatusServiceUnavailable )
32
- return
33
- }
34
- defer serverConn .Close ()
35
-
36
- hj , ok := w .(http.Hijacker )
37
- if ! ok {
38
- log .Error ("hijack of connection failed" )
39
- http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
40
- return
41
- }
42
-
43
- w .WriteHeader (http .StatusOK )
44
-
45
- clientConn , bufClientConn , err := hj .Hijack ()
46
- if err != nil {
47
- log .Error (err )
48
- http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
49
- return
50
- }
51
- defer clientConn .Close ()
52
-
53
- go io .Copy (serverConn , bufClientConn )
54
- io .Copy (bufClientConn , serverConn )
55
- }
56
-
57
- func forward (w http.ResponseWriter , r * http.Request ) {
58
- resp , err := http .DefaultTransport .RoundTrip (r )
59
- if err != nil {
60
- log .Error (err )
61
- http .Error (w , http .StatusText (http .StatusServiceUnavailable ), http .StatusServiceUnavailable )
62
- return
63
- }
64
- for header , values := range resp .Header {
65
- for _ , value := range values {
66
- w .Header ().Add (header , value )
67
- }
68
- }
69
- w .WriteHeader (resp .StatusCode )
70
- io .Copy (w , resp .Body )
71
- }
72
-
73
24
func CreateHttpProxyServer (TargetConn * websocket.Conn , Port string , rch chan define.RelayCommandResp , stop chan struct {}) {
74
25
var (
75
26
caCertFile = "cert/cert.pem"
0 commit comments