Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion go/gosdk/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions go/gosdk/gosdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 24 additions & 18 deletions go/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions go/passthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading