Skip to content

Commit

Permalink
[Release] Add location, rewrite and fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluemangoo authored May 1, 2024
1 parent fb53c10 commit ea27018
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 81 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release

on:
push:
branches: []
branches: ["master"]
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -31,7 +31,6 @@ jobs:
strategy:
matrix:
target:
- aarch64-apple-ios
- aarch64-apple-darwin
- aarch64-linux-android
- aarch64-unknown-linux-gnu
Expand All @@ -41,16 +40,11 @@ jobs:
- armv7-unknown-linux-musleabihf
- i686-unknown-linux-gnu
- i686-unknown-linux-musl
- riscv64gc-unknown-linux-gnu
- x86_64-apple-darwin
- x86_64-unknown-linux-musl
- x86_64-unknown-linux-gnu

include:
- target: aarch64-apple-ios
host_os: ubuntu-latest
cross: true

- target: aarch64-apple-darwin
host_os: macos-latest

Expand Down Expand Up @@ -86,10 +80,6 @@ jobs:
host_os: ubuntu-latest
cross: true

- target: riscv64gc-unknown-linux-gnu
host_os: ubuntu-latest
cross: true

- target: x86_64-apple-darwin
host_os: macos-latest

Expand Down
11 changes: 10 additions & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pingpong"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -14,3 +14,6 @@ toml = "0.8.12"
serde = { version = "1.0.198", features = ["derive"] }
simplelog = "0.12.2"
anyhow = "1.0.82"
regex = "1.10.4"
http = "1.1.0"
urlencoding = "2.1.3"
53 changes: 49 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Properties of Server

- `thread`: Thread for this server.
- `source`: `Map<String, Source>`. Importable, and each source is also importable.
- `check_status`: Optional, default false, check if source is available, and speedup when unavailable.
- `check_duration`: Optional, default 1000, duration of per status check (ms).

Properties of Source:

Expand All @@ -59,25 +61,68 @@ Properties of Source:
- `host`: Optional, rewrite `Host` in request headers. Fill if upstream service also use sni to recognize route.
- `headers_request`: `Map<String, String>`. Optional and importable, add or replace the header in request.
- `headers_response`: `Map<String, String>`. Optional and importable, add or replace the header in response.
- `location`: Optional, default to match all the requests, see [Location](#location).
- `rewrite`: Optional, see [Rewrite](#rewrite).
- `fallback`: Optional, fallback to other sources when available, only works when `check_status` is enabled.

### Location

Location syntax is similar to [Nginx](https://nginx.org/r/location), but here you provide a list of location pattern.

Matching is after decoding the text encoded in the “%XX” form.

Syntax: `[ = | ^ | ~ ] URI`.

There are three type: `=`(equal), `^`(startsWith) and `~`(regex).

**There is a space between type and URI.**

When no type is provided and uri is starts with `/`, type will be `^`(startsWith).

*Why the hell a URI will start without `/`??*

For example:

```toml
location = ["/public", "~ /static/*.(gif|jpg|jpeg)"]
```

### Rewrite

Rewrite syntax is similar to [Nginx](https://nginx.org/r/rewrite), but here you provide a list of rewrite pattern.

Matching is after decoding the text encoded in the “%XX” form.

Syntax: `rewrite-regex URI [flag]`.

An optional `flag` parameter can be one of:
- `last`: The default one, stops processing the current set of rewrite and starts a search for a new location matching the changed URI;
- `break`: stops processing the current rewrite rule and start to search next.

For example:

```toml
rewrite = ["^/(.*) /service2/$1 last"]
```

## Build

**You can find the latest build in [Actions](https://github.com/Bluemangoo/Pingpong/actions/workflows/build.yml).**
**You can find the latest x86_64 build in [Actions](https://github.com/Bluemangoo/Pingpong/actions/workflows/build.yml).**

Makesure you have cargo and rustc installed.
Make sure you have cargo and rustc installed.

### Build from scratch

```bash
cargo build
```

If successful, you can find the excutable binary here: `target/debug/pingpong`
If successful, you can find the executable binary here: `target/debug/pingpong`

### Build optimised one

```bash
cargo build --release
```

If successful, you can find the excutable binary here: `target/release/pingpong`
If successful, you can find the executable binary here: `target/release/pingpong`
13 changes: 9 additions & 4 deletions config/server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
threads = 5 # optional.
#sni.cert = "/path/to/cert.pem" # optional.
#sni.key = "/path/to/cert.key" # optional.
#check_status = true # optional, check if source is available, and speedup when unavailable
#check_duration = 1000 # optional, check duration (ms)

[6188.source.service1] # importable structure
ip = "127.0.0.1"
Expand All @@ -12,7 +14,10 @@ ssl = false
ip = "127.18.0.2"
port = 40201
ssl = false
sni = "dev.bluemangoo.net" # optional. The unset one is default.
host = "dev.bluemangoo.net" # optional, rewrite `Host` in request headers.
headers_request = { } # optional and importable, add or replace the header in request
headers_response = { } # optional and importable, add or replace the header in upstream response
sni = "dev.bluemangoo.net" # optional. The unset one is default.
host = "dev.bluemangoo.net" # optional, rewrite `Host` in request headers.
headers_request = { } # optional and importable, add or replace the header in request
headers_response = { } # optional and importable, add or replace the header in upstream response
location = ["/"] # optional, see the documents.
#rewrite = ["^/(.*) /service2/$1 break"] # optional, see the documents
#fallback = ["services1"] # optional, see the documents.
Loading

0 comments on commit ea27018

Please sign in to comment.