diff --git a/go/gosdk/abi.go b/go/gosdk/abi.go index 9ba223f..351e0dd 100644 --- a/go/gosdk/abi.go +++ b/go/gosdk/abi.go @@ -298,7 +298,8 @@ func envoy_dynamic_module_on_http_filter_http_callout_done( func envoy_dynamic_module_on_http_filter_scheduled( filterEnvoyPtr uintptr, filterModulePtr uintptr, - eventID C.uint64_t) { + eventID C.uint64_t, +) { pinned := unwrapPinnedHttpFilter(uintptr(filterModulePtr)) // Call the Scheduled method of the filter. pinned.obj.Scheduled(envoyFilter{raw: uintptr(filterEnvoyPtr)}, uint64(eventID)) @@ -469,6 +470,12 @@ func (e envoyFilter) GetSourceAddress() string { return e.getStringAttribute(24) // source.address } +// GetDestinationAddress implements [EnvoyHttpFilter]. +func (e envoyFilter) GetDestinationAddress() string { + // https://github.com/envoyproxy/envoy/blob/05223ee2cd143d70b32402783c2a866a9dd18bd1/source/extensions/dynamic_modules/abi.h#L237-L372 + return e.getStringAttribute(26) // destination.address +} + func (e envoyFilter) getStringAttribute(id int) string { var resultBufferPtr *byte var resultBufferLengthPtr int diff --git a/go/gosdk/gosdk.go b/go/gosdk/gosdk.go index 1349be5..74fd00b 100644 --- a/go/gosdk/gosdk.go +++ b/go/gosdk/gosdk.go @@ -59,6 +59,9 @@ type EnvoyHttpFilter interface { // GetSourceAddress gets the source address of the request in the format of "IP:PORT". // This corresponds to `source.address` attribute https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes. GetSourceAddress() string + // GetDestinationAddress gets the destination address of the request in the format of "IP:PORT". + // This corresponds to `destination.address` attribute https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes. + GetDestinationAddress() string // GetRequestProtocol gets the request protocol. This corresponds to `request.protocol` attribute https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes. GetRequestProtocol() string // NewScheduler creates a new Scheduler that can be used to schedule events to the correct Envoy worker thread. diff --git a/go/mock_test.go b/go/mock_test.go index 64f4b57..0f0b0d5 100644 --- a/go/mock_test.go +++ b/go/mock_test.go @@ -8,24 +8,25 @@ import ( // mockEnvoyHttpFilter is a mock implementation of [gosdk.EnvoyHttpFilter] for testing. type mockEnvoyHttpFilter struct { - getRequestHeader func(key string) (string, bool) - getRequestHeaders func() map[string][]string - setRequestHeader func(key string, value []byte) bool - getResponseHeader func(key string) (string, bool) - getResponseHeaders func() map[string][]string - setResponseHeader func(key string, value []byte) bool - getRequestBody func() (io.Reader, bool) - drainRequestBody func(n int) bool - appendRequestBody func(data []byte) bool - getResponseBody func() (io.Reader, bool) - drainResponseBody func(n int) bool - appendResponseBody func(data []byte) bool - sendLocalReply func(statusCode uint32, headers [][2]string, body []byte) - getSourceAddress func() string - getRequestProtocol func() string - newScheduler func() gosdk.Scheduler - continueRequest func() - continueResponse func() + getRequestHeader func(key string) (string, bool) + getRequestHeaders func() map[string][]string + setRequestHeader func(key string, value []byte) bool + getResponseHeader func(key string) (string, bool) + getResponseHeaders func() map[string][]string + setResponseHeader func(key string, value []byte) bool + getRequestBody func() (io.Reader, bool) + drainRequestBody func(n int) bool + appendRequestBody func(data []byte) bool + getResponseBody func() (io.Reader, bool) + drainResponseBody func(n int) bool + appendResponseBody func(data []byte) bool + sendLocalReply func(statusCode uint32, headers [][2]string, body []byte) + getSourceAddress func() string + getDestinationAddress func() string + getRequestProtocol func() string + newScheduler func() gosdk.Scheduler + continueRequest func() + continueResponse func() } // GetRequestHeader implements [gosdk.EnvoyHttpFilter.GetRequestHeader]. @@ -98,6 +99,11 @@ func (m mockEnvoyHttpFilter) GetSourceAddress() string { return m.getSourceAddress() } +// GetDestinationAddress implements [gosdk.EnvoyHttpFilter.GetDestinationAddress]. +func (m mockEnvoyHttpFilter) GetDestinationAddress() string { + return m.getDestinationAddress() +} + // GetRequestProtocol implements [gosdk.EnvoyHttpFilter.GetRequestProtocol]. func (m mockEnvoyHttpFilter) GetRequestProtocol() string { return m.getRequestProtocol() diff --git a/go/passthrough.go b/go/passthrough.go index f314719..d0ffd0a 100644 --- a/go/passthrough.go +++ b/go/passthrough.go @@ -37,6 +37,7 @@ func (p passthroughFilter) RequestHeaders(e gosdk.EnvoyHttpFilter, endOfStream b } } fmt.Printf("gosdk: RequestHeaders, source address: %s\n", e.GetSourceAddress()) + fmt.Printf("gosdk: RequestHeaders, destination address: %s\n", e.GetDestinationAddress()) fmt.Printf("gosdk: RequestHeaders, request protocol: %s\n", e.GetRequestProtocol()) return gosdk.RequestHeadersStatusContinue }