Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
readme and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
M4tteoP committed Dec 22, 2023
1 parent 57d1c96 commit f29815f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
30 changes: 21 additions & 9 deletions examples/http_body_chunk/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
## http_body

this example demonstrates how to perform operation on a request body, chunk by chunk.
This example demonstrates how to perform operations on a request body, chunk by chunk.

# TODO!
To modify the request:
Reading the received body chunk by chunk, it looks for the string "pattern" inside the body. If it finds it, a 403 response is returned providing the number of the chunk where the pattern was found. Logs are printed every time a chunk is received providing also the size of the read chunk.

Build and run the example:
```bash
$ make build.example name=http_body_chunk
$ make run name=http_body_chunk
```
$ curl -XPUT localhost:18000 --data '[initial body]' -H "buffer-operation: prepend"
[this is prepended body][initial body]

$ curl -XPUT localhost:18000 --data '[initial body]' -H "buffer-operation: append"
[initial body][this is appended body]
Perform a request with a body containing the string "pattern":
```bash
$ head -c 700000 /dev/urandom | base64 > /tmp/file.txt && echo "pattern" >> /tmp/file.txt && curl 'localhost:18000/anything' -d @/tmp/file.txt
pattern found in chunk: 2
```

$ curl -XPUT localhost:18000 --data '[initial body]' -H "buffer-operation: replace"
[this is replaced body]
Logs generated:
```
wasm log: OnHttpRequestBody called. BodySize: 114532, totalRequestBodyReadSize: 0, endOfStream: false
wasm log: read chunk size: 114532
wasm log: OnHttpRequestBody called. BodySize: 114532, totalRequestBodyReadSize: 114532, endOfStream: false
wasm log: OnHttpRequestBody called. BodySize: 933343, totalRequestBodyReadSize: 114532, endOfStream: true
wasm log: read chunk size: 818811
wasm log: pattern found in chunk: 2
wasm log: local 403 response sent
```
3 changes: 2 additions & 1 deletion proxywasm/proxytest/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func TestBodyBuffering(t *testing.T) {
name: "buffered",
buffered: true,
action: types.ActionPause,
logged: "1111122222",
// The first chunk has been buffered, therefore it will be retrieved when calling GetHttpRequestBody at the end of stream.
logged: "1111122222",
},
{
name: "unbuffered",
Expand Down

0 comments on commit f29815f

Please sign in to comment.