mirror of
https://github.com/1f349/violet.git
synced 2024-11-23 11:51:37 +00:00
Start and stop logs for hybrid transport calls
This commit is contained in:
parent
53041f4ac7
commit
869d114891
1
go.mod
1
go.mod
@ -11,6 +11,7 @@ require (
|
|||||||
github.com/MrMelon54/rescheduler v0.0.1
|
github.com/MrMelon54/rescheduler v0.0.1
|
||||||
github.com/MrMelon54/trie v0.0.2
|
github.com/MrMelon54/trie v0.0.2
|
||||||
github.com/google/subcommands v1.2.0
|
github.com/google/subcommands v1.2.0
|
||||||
|
github.com/google/uuid v1.3.1
|
||||||
github.com/gorilla/websocket v1.5.0
|
github.com/gorilla/websocket v1.5.0
|
||||||
github.com/julienschmidt/httprouter v1.3.0
|
github.com/julienschmidt/httprouter v1.3.0
|
||||||
github.com/mattn/go-sqlite3 v1.14.16
|
github.com/mattn/go-sqlite3 v1.14.16
|
||||||
|
2
go.sum
2
go.sum
@ -23,6 +23,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOW
|
|||||||
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||||
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
|
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
|
||||||
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||||
|
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
||||||
|
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
|
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
|
||||||
|
@ -3,6 +3,8 @@ package proxy
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"github.com/1f349/violet/proxy/websocket"
|
"github.com/1f349/violet/proxy/websocket"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
@ -67,15 +69,24 @@ func NewHybridTransportWithCalls(normal, insecure http.RoundTripper, ws *websock
|
|||||||
|
|
||||||
// SecureRoundTrip calls the secure transport
|
// SecureRoundTrip calls the secure transport
|
||||||
func (h *HybridTransport) SecureRoundTrip(req *http.Request) (*http.Response, error) {
|
func (h *HybridTransport) SecureRoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
u := uuid.New()
|
||||||
|
log.Println("[Transport] Start upgrade:", u)
|
||||||
|
defer log.Println("[Transport] Stop upgrade:", u)
|
||||||
return h.normalTransport.RoundTrip(req)
|
return h.normalTransport.RoundTrip(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsecureRoundTrip calls the insecure transport
|
// InsecureRoundTrip calls the insecure transport
|
||||||
func (h *HybridTransport) InsecureRoundTrip(req *http.Request) (*http.Response, error) {
|
func (h *HybridTransport) InsecureRoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
u := uuid.New()
|
||||||
|
log.Println("[Transport insecure] Start upgrade:", u)
|
||||||
|
defer log.Println("[Transport insecure] Stop upgrade:", u)
|
||||||
return h.insecureTransport.RoundTrip(req)
|
return h.insecureTransport.RoundTrip(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectWebsocket calls the websocket upgrader and thus hijacks the connection
|
// ConnectWebsocket calls the websocket upgrader and thus hijacks the connection
|
||||||
func (h *HybridTransport) ConnectWebsocket(rw http.ResponseWriter, req *http.Request) {
|
func (h *HybridTransport) ConnectWebsocket(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
u := uuid.New()
|
||||||
|
log.Println("[Websocket] Start upgrade:", u)
|
||||||
h.ws.Upgrade(rw, req)
|
h.ws.Upgrade(rw, req)
|
||||||
|
log.Println("[Websocket] Stop upgrade:", u)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user