Skip to content

Commit

Permalink
Merge pull request #3 from RicYaben/middlewares
Browse files Browse the repository at this point in the history
Apply middlewares before dialing
  • Loading branch information
RicYaben authored Jan 15, 2023
2 parents 246c9f0 + 28addea commit 9fe01f1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ workspace*.code-*
# Transit folders
/vendor/
/bin/
/tcpdump/

# whatever the rules are, include all the `.md` files
!*.md
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 6 additions & 3 deletions internal/proxy/tcpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func (tcpProxy *TCPProxy) Start() (err error) {
}
defer client.Close()

// Apply the middlewares to the connection before dialing the server
_, err = tcpProxy.middlewares.Apply(client)
if err != nil {
return
}

// Get a connection to the server for each new connection with the client
server, servErr := net.DialTimeout(globals.TCP.String(), tcpProxy.service.GetAddress(), 1*time.Second)

Expand All @@ -65,9 +71,6 @@ func (tcpProxy *TCPProxy) Start() (err error) {
tcpProxy.wg.Add(1)

go func() {
// Apply the middlewares to the connection
tcpProxy.middlewares.Apply(client)

// Handle the connection between the client and the server
// NOTE: The handlers will defer the connections
tcpProxy.handle(client, server)
Expand Down

0 comments on commit 9fe01f1

Please sign in to comment.