Skip to content

Commit 487a6e2

Browse files
authored
Add SourceAddr support (#32)
* Add RemoteAddr support * use SourceAddr
1 parent 27f49b7 commit 487a6e2

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

handler/api/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ type Request interface {
121121
// Headers allows access to any incoming request headers.
122122
Headers() Header
123123

124+
// GetSourceAddr returns client SourceAddr.
125+
GetSourceAddr() string
126+
124127
// Body allows access to any incoming request body. To read this without
125128
// preventing the Next from reading it, enable FeatureBufferRequest.
126129
Body() Body

handler/internal/imports/host.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,7 @@ func GetStatusCode() uint32 {
178178
func SetStatusCode(statusCode uint32) {
179179
setStatusCode(statusCode)
180180
}
181+
182+
func GetSourceAddr(ptr uint32, limit BufLimit) (len uint32) {
183+
return getSourceAddr(ptr, limit)
184+
}

handler/internal/imports/imports.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ func getStatusCode() uint32
5757

5858
//go:wasmimport http_handler set_status_code
5959
func setStatusCode(statusCode uint32)
60+
61+
//go:wasmimport http_handler get_source_addr
62+
func getSourceAddr(ptr uint32, limit BufLimit) (len uint32)

handler/internal/imports/imports_stub.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ func getStatusCode() uint32 {
7777

7878
// setStatusCode is stubbed for compilation outside TinyGo.
7979
func setStatusCode(statusCode uint32) {}
80+
81+
// getSourceAddr is stubbed for compilation outside TinyGo.
82+
func getSourceAddr(ptr uint32, limit BufLimit) (len uint32) {
83+
return 0
84+
}

handler/request.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ func (wasmRequest) Body() api.Body {
5757
func (wasmRequest) Trailers() api.Header {
5858
return wasmRequestTrailers
5959
}
60+
61+
// GetSourceAddr implements the same method as documented on api.Request.
62+
func (wasmRequest) GetSourceAddr() string {
63+
return mem.GetString(imports.GetSourceAddr)
64+
}

0 commit comments

Comments
 (0)