Comments (10)
Hi all, I implemented the API by @pwoelfle as in #117 (comment), and believe fixed this issue.
Please take a look at this example https://github.com/tetratelabs/proxy-wasm-go-sdk/tree/main/examples/http_body for detail. Thanks!
from proxy-wasm-go-sdk.
@FrimIdan No there is no limitation in Envoy. The buffer can be replaced - even with a shorter length - but the length
argument must be equal or greater than the current buffer size (see here).
From my perspective, the Proxy WASM SetHttpRequestBody
could be changed towards something similar which I posted above to fit the Envoy logic.
from proxy-wasm-go-sdk.
image: istio/proxyv2:1.8.2
GolangVersion:"go1.15.5"
I get the same response from the SetHttpResponseBody function.
b := []byte(mynewBody)
err = SetHTTPResponseBody(b)
if err != nil {
proxywasm.LogErrorf("failed to set response body: %v", err)
return types.ActionContinue
}
log output
[2021-02-05 13:38:53.257][19][error][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1154] wasm log: failed to set response body: error status returned by host: bad argument
from proxy-wasm-go-sdk.
@FalkFiedler
maybe that`s the reason https://github.com/proxy-wasm/proxy-wasm-cpp-host/blob/49ed20e895b728aae6b811950a2939ecbaf76f7c/include/proxy-wasm/context.h#L82-L86
from proxy-wasm-go-sdk.
I got the same issue on Envoy v1.17.0. The root cause (at least for my problem) was found here: https://github.com/envoyproxy/envoy/blob/v1.17.0/source/extensions/common/wasm/context.cc#L122-L146
Envoy supports the following buffer manipulations:
- prepend:
start
andlength
needs to be zero - append:
start
needs to be greater or equal to the origin buffer size - replace:
start
needs to be zero andlength
must be greater or equal to the origin buffer size <- here the whole buffer is drained and then the new data are set
The current Proxy WASM Go SDK SetHttpRequestBody
implementation assumes that the new body is always equal or greater than the origin body. If it is not the case the envoy returns a bad argument error.
According to this I tested the following successfully:
body
is the data which should prepend, append or replace
bodySize
is the origin body size given by the OnHttpRequestBody
hook.
func PrependToHttpRequestBody(body []byte, bodySize int) (int, error) {
var bufferData *byte
if len(body) != 0 {
bufferData = &body[0]
}
st := rawhostcall.ProxySetBufferBytes(types.BufferTypeHttpRequestBody, 0, 0, bufferData, len(body))
if st != types.StatusOK {
return -1, types.StatusToError(st)
}
return bodySize + len(body), nil
}
func AppendToHttpRequestBody(body []byte, bodySize int) (int, error) {
var bufferData *byte
if len(body) != 0 {
bufferData = &body[0]
}
st := rawhostcall.ProxySetBufferBytes(types.BufferTypeHttpRequestBody, bodySize, 0, bufferData, len(body))
if st != types.StatusOK {
return -1, types.StatusToError(st)
}
return bodySize + len(body), nil
}
func ReplaceHttpRequestBody(body []byte, bodySize int) (int, error) {
var bufferData *byte
if len(body) != 0 {
bufferData = &body[0]
}
st := rawhostcall.ProxySetBufferBytes(types.BufferTypeHttpRequestBody, 0, bodySize, bufferData, len(body))
if st != types.StatusOK {
return -1, types.StatusToError(st)
}
return len(body), nil
}
from proxy-wasm-go-sdk.
@pwoelfle do you have a working example with the body manipulation ?
I'm trying to implement a modification of the response body and I get some issues with the fact that I need to update the content-length and can't find a way to do it properly (using ActionPause, ...).
from proxy-wasm-go-sdk.
@djannot I faced the same problem. It's not possible to adjust the Content-Length HTTP header. You have to remove this header.
See also in the Rust SDK: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/blob/v0.1.3/examples/http_body.rs#L48
from proxy-wasm-go-sdk.
@djannot You will have to remove Content-Length header from HTTP response headers.
Using wasm go sdk; check this: https://github.com/abhide/envoy-wasm-experiments/blob/main/main.go#L72
The issue happens on the http client side; where the only a part of the output (equal to Content-length) gets read and output looks truncated.
I haven't tried setting Content-Length to be equal to sum of original content-length + length introduced by changes from within the wasm filter.
from proxy-wasm-go-sdk.
@abhide that's what I've done at the end, because I wasn't able to update the value
from proxy-wasm-go-sdk.
@pwoelfle So there is a limitation in Envoy and set buffer can't replace the current buffer with a shorter one?
Did you find/opened an issue in Envoy for it?
from proxy-wasm-go-sdk.
Related Issues (20)
- OnHttpResponseBody will buffer the whole body when ActionPause returned before HOT 5
- Is it possible to build a filter that get the body content and save as header per request? HOT 4
- Is it possible to make HTTPS calls using DipatchHttpCall HOT 1
- when ResumeHttpResponse make envoy crash HOT 1
- How to get the source workload name info๏ผ HOT 1
- Difference between different SDKs. HOT 1
- ActionPause will not pause the processing in the filter chain HOT 1
- new release of the repo HOT 2
- Question: Adding Data to SYN Packet
- wasm-plugin does not work except 'istio-proxy' namepsace HOT 2
- readme example build error HOT 2
- Wasm Filter Bad Argument Error returned by DispatchHttpCall Method HOT 1
- Redis connection HOT 4
- Question: proxywasm.GetHttpRequestHeaders() is returning error code = 6 HOT 1
- How run test for mac (intel) ? HOT 1
- Circuit breaking the specific requests
- Question: Can DispatchHttpCall be used in OnHTTPStreamDone? HOT 2
- Question: Generic cluster for DispatchHttpCall?
- Cannot access plugin config in network context. HOT 1
- Debug and Info logs are not shown HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proxy-wasm-go-sdk.