From 04c9b51e735838a3b12416a8ff1b09d0b3c2f84c Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 21:58:33 +0100 Subject: [PATCH 1/3] Disable test plugin --- gatewayd_plugins.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatewayd_plugins.yaml b/gatewayd_plugins.yaml index 237c9c5b..5002d0e2 100644 --- a/gatewayd_plugins.yaml +++ b/gatewayd_plugins.yaml @@ -9,7 +9,7 @@ plugins: # Plugin name - name: gatewayd-plugin-test # whether to enable or disable the plugin on the next run - enabled: True + enabled: False # path to the plugin's binary file localPath: ../gatewayd-plugin-test/gatewayd-plugin-test # Pass cmdline args to the plugin From 176660a49bce14dda3c3ce8c8584bda9acb64aa7 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 21:58:51 +0100 Subject: [PATCH 2/3] Enable color output in logger --- gatewayd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatewayd.yaml b/gatewayd.yaml index 625a611c..0c467b77 100644 --- a/gatewayd.yaml +++ b/gatewayd.yaml @@ -7,7 +7,7 @@ loggers: # Implementing file output # file : ./logs/gatewayd.log level: "debug" # panic, fatal, error, warn, info, debug, trace - noColor: True + noColor: False timeFormat: "unix" clients: From c9bcadeb9ab8ecfab8fd8f12c19b324614dde998 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 22:11:39 +0100 Subject: [PATCH 3/3] Implement OnTrafficToClient --- network/proxy.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/network/proxy.go b/network/proxy.go index 70153878..1e73a761 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -427,7 +427,33 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { // TODO: Implement OnTrafficToClient hooks. // Send the response to the client. - return sendTrafficToClient(response, received) + errVerdict := sendTrafficToClient(response, received) + + // Run the OnTrafficToClient hooks. + _, err = pr.hookConfig.Run( + context.Background(), + trafficData( + gconn, + client, + []Field{ + { + Name: "request", + Value: request, + }, + { + Name: "response", + Value: response[:received], + }, + }, + err, + ), + hook.OnTrafficToClient, + pr.hookConfig.Verification) + if err != nil { + pr.logger.Error().Err(err).Msg("Error running hook") + } + + return errVerdict } // IsHealty checks if the pool is exhausted or the client is disconnected.