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
3 changes: 3 additions & 0 deletions handler/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ type Request interface {
// Headers allows access to any incoming request headers.
Headers() Header

// GetSourceAddr returns client SourceAddr.
GetSourceAddr() string

// Body allows access to any incoming request body. To read this without
// preventing the Next from reading it, enable FeatureBufferRequest.
Body() Body
Expand Down
4 changes: 4 additions & 0 deletions handler/internal/imports/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,7 @@ func GetStatusCode() uint32 {
func SetStatusCode(statusCode uint32) {
setStatusCode(statusCode)
}

func GetSourceAddr(ptr uint32, limit BufLimit) (len uint32) {
return getSourceAddr(ptr, limit)
}
3 changes: 3 additions & 0 deletions handler/internal/imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ func getStatusCode() uint32

//go:wasmimport http_handler set_status_code
func setStatusCode(statusCode uint32)

//go:wasmimport http_handler get_source_addr
func getSourceAddr(ptr uint32, limit BufLimit) (len uint32)
5 changes: 5 additions & 0 deletions handler/internal/imports/imports_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ func getStatusCode() uint32 {

// setStatusCode is stubbed for compilation outside TinyGo.
func setStatusCode(statusCode uint32) {}

// getSourceAddr is stubbed for compilation outside TinyGo.
func getSourceAddr(ptr uint32, limit BufLimit) (len uint32) {
return 0
}
5 changes: 5 additions & 0 deletions handler/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ func (wasmRequest) Body() api.Body {
func (wasmRequest) Trailers() api.Header {
return wasmRequestTrailers
}

// GetSourceAddr implements the same method as documented on api.Request.
func (wasmRequest) GetSourceAddr() string {
return mem.GetString(imports.GetSourceAddr)
}