This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters