Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 272ab09

Browse files
author
Wim Spaargaren
committed
chore: expose ProxySetBufferBytes correctly & implement high level api for setting request and response body
1 parent 9bc9e32 commit 272ab09

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

proxytest/proxytest.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ func (h *hostEmulator) ProxyGetBufferBytes(bt types.BufferType, start int, maxSi
116116
}
117117
}
118118

119+
func (h *hostEmulator) ProxySetBufferBytes(bt types.BufferType, start int, maxSize int, bufferData *byte, bufferSize int) types.Status {
120+
// TODO: implement host emulator set buffer bytes
121+
return types.StatusOK
122+
}
123+
119124
// impl rawhostcall.ProxyWASMHost
120125
func (h *hostEmulator) ProxyGetHeaderMapValue(mapType types.MapType, keyData *byte,
121126
keySize int, returnValueData **byte, returnValueSize *int) types.Status {

proxywasm/hostcall.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ func GetHttpRequestBody(start, maxSize int) ([]byte, error) {
128128
return ret, types.StatusToError(st)
129129
}
130130

131+
func SetHttpRequestBody(body []byte) error {
132+
if len(body) == 0 {
133+
return types.StatusToError(types.StatusBadArgument)
134+
}
135+
bufferData := &body[0]
136+
st := rawhostcall.ProxySetBufferBytes(types.BufferTypeHttpRequestBody, 0, len(body), bufferData, len(body))
137+
return types.StatusToError(st)
138+
}
139+
131140
func GetHttpRequestTrailers() ([][2]string, error) {
132141
ret, st := getMap(types.MapTypeHttpRequestTrailers)
133142
return ret, types.StatusToError(st)
@@ -189,6 +198,15 @@ func GetHttpResponseBody(start, maxSize int) ([]byte, error) {
189198
return ret, types.StatusToError(st)
190199
}
191200

201+
func SetHttpResponseBody(body []byte) error {
202+
if len(body) == 0 {
203+
return types.StatusToError(types.StatusBadArgument)
204+
}
205+
bufferData := &body[0]
206+
st := rawhostcall.ProxySetBufferBytes(types.BufferTypeHttpResponseBody, 0, len(body), bufferData, len(body))
207+
return types.StatusToError(st)
208+
}
209+
192210
func GetHttpResponseTrailers() ([][2]string, error) {
193211
ret, st := getMap(types.MapTypeHttpResponseTrailers)
194212
return ret, types.StatusToError(st)

proxywasm/rawhostcall/rawhostcall_mock.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type ProxyWASMHost interface {
4444
ProxyGetHeaderMapPairs(mapType types.MapType, returnValueData **byte, returnValueSize *int) types.Status
4545
ProxySetHeaderMapPairs(mapType types.MapType, mapData *byte, mapSize int) types.Status
4646
ProxyGetBufferBytes(bt types.BufferType, start int, maxSize int, returnBufferData **byte, returnBufferSize *int) types.Status
47+
ProxySetBufferBytes(bt types.BufferType, start int, maxSize int, bufferData *byte, bufferSize int) types.Status
4748
ProxyHttpCall(upstreamData *byte, upstreamSize int, headerData *byte, headerSize int, bodyData *byte, bodySize int, trailersData *byte, trailersSize int, timeout uint32, calloutIDPtr *uint32) types.Status
4849
ProxySetTickPeriodMilliseconds(period uint32) types.Status
4950
ProxyGetCurrentTimeNanoseconds(returnTime *int64) types.Status
@@ -112,6 +113,9 @@ func (d DefaultProxyWAMSHost) ProxySetHeaderMapPairs(mapType types.MapType, mapD
112113
func (d DefaultProxyWAMSHost) ProxyGetBufferBytes(bt types.BufferType, start int, maxSize int, returnBufferData **byte, returnBufferSize *int) types.Status {
113114
return 0
114115
}
116+
func (d DefaultProxyWAMSHost) ProxySetBufferBytes(bt types.BufferType, start int, maxSize int, bufferData *byte, bufferSize int) types.Status {
117+
return 0
118+
}
115119
func (d DefaultProxyWAMSHost) ProxyHttpCall(upstreamData *byte, upstreamSize int, headerData *byte, headerSize int, bodyData *byte, bodySize int, trailersData *byte, trailersSize int, timeout uint32, calloutIDPtr *uint32) types.Status {
116120
return 0
117121
}
@@ -209,6 +213,10 @@ func ProxyGetBufferBytes(bt types.BufferType, start int, maxSize int, returnBuff
209213
return currentHost.ProxyGetBufferBytes(bt, start, maxSize, returnBufferData, returnBufferSize)
210214
}
211215

216+
func ProxySetBufferBytes(bt types.BufferType, start int, maxSize int, bufferData *byte, bufferSize int) types.Status {
217+
return currentHost.ProxySetBufferBytes(bt, start, maxSize, bufferData, bufferSize)
218+
}
219+
212220
func ProxyHttpCall(upstreamData *byte, upstreamSize int, headerData *byte, headerSize int, bodyData *byte,
213221
bodySize int, trailersData *byte, trailersSize int, timeout uint32, calloutIDPtr *uint32) types.Status {
214222
return currentHost.ProxyHttpCall(upstreamData, upstreamSize,

0 commit comments

Comments
 (0)