Skip to content

Commit

Permalink
feat: implements text/event-stream(SSE) MIME parser (#1416)
Browse files Browse the repository at this point in the history
Co-authored-by: 007gzs <[email protected]>
  • Loading branch information
jizhuozhi and 007gzs authored Oct 24, 2024
1 parent cdd7115 commit e7561c3
Show file tree
Hide file tree
Showing 13 changed files with 885 additions and 6 deletions.
13 changes: 7 additions & 6 deletions plugins/wasm-rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ IMAGE_TAG = $(if $(strip $(PLUGIN_VERSION)),${PLUGIN_VERSION},${BUILD_TIME}-${CO
IMG ?= ${REGISTRY}${PLUGIN_NAME}:${IMAGE_TAG}

.DEFAULT:
lint-base:
cargo fmt --all --check
cargo clippy --workspace --all-features --all-targets
lint:
cargo fmt --all --check --manifest-path extensions/${PLUGIN_NAME}/Cargo.toml
cargo clippy --workspace --all-features --all-targets --manifest-path extensions/${PLUGIN_NAME}/Cargo.toml
build:
DOCKER_BUILDKIT=1 docker build \
--build-arg PLUGIN_NAME=${PLUGIN_NAME} \
Expand All @@ -20,3 +14,10 @@ build:
.
@echo ""
@echo "output wasm file: extensions/${PLUGIN_NAME}/plugin.wasm"

lint-base:
cargo fmt --all --check
cargo clippy --workspace --all-features --all-targets
lint:
cargo fmt --all --check --manifest-path extensions/${PLUGIN_NAME}/Cargo.toml
cargo clippy --workspace --all-features --all-targets --manifest-path extensions/${PLUGIN_NAME}/Cargo.toml
270 changes: 270 additions & 0 deletions plugins/wasm-rust/example/sse-timing/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions plugins/wasm-rust/example/sse-timing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "sse-timing"
version = "0.1.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]

[dependencies]
higress-wasm-rust = { path = "../../", version = "0.1.0" }
proxy-wasm = { git="https://github.com/higress-group/proxy-wasm-rust-sdk", branch="main", version="0.2.2" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
10 changes: 10 additions & 0 deletions plugins/wasm-rust/example/sse-timing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BUILD_OPTS="--release"

.DEFAULT:
build:
cargo build --target wasm32-wasi ${BUILD_OPTS}
find target -name "*.wasm" -d 3 -exec cp "{}" plugin.wasm \;

clean:
cargo clean
rm -f plugin.wasm
26 changes: 26 additions & 0 deletions plugins/wasm-rust/example/sse-timing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Proxy-Wasm plugin example: SSE Timing

Proxy-Wasm plugin that traces Server-Side Event(SSE) duration from request start.

### Building

```sh
$ make
```

### Using in Envoy

This example can be run with [`docker compose`](https://docs.docker.com/compose/install/)
and has a matching Envoy configuration.

```sh
$ docker compose up
```

#### Access granted.

Send HTTP request to `localhost:10000/`:

```sh
$ curl localhost:10000/
```
35 changes: 35 additions & 0 deletions plugins/wasm-rust/example/sse-timing/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2023 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

services:
envoy:
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/all-in-one:latest
entrypoint: /usr/local/bin/envoy
command: -c /etc/envoy/envoy.yaml --component-log-level wasm:debug
depends_on:
- sse-server
hostname: envoy
ports:
- "10000:10000"
volumes:
- ./envoy.yaml:/etc/envoy/envoy.yaml
- ./target/wasm32-wasi/release:/etc/envoy/proxy-wasm-plugins
networks:
- envoymesh
sse-server:
build: sse-server
networks:
- envoymesh
networks:
envoymesh: {}
Loading

0 comments on commit e7561c3

Please sign in to comment.