-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(deps): bump fgw to 1.5.3 (#628)
* build(deps): bump fgw to 1.5.3 Signed-off-by: Lin Yang <reaver@flomesh.io> * fix: make package-scripts Signed-off-by: Lin Yang <reaver@flomesh.io> * fix: make package-scripts Signed-off-by: Lin Yang <reaver@flomesh.io> --------- Signed-off-by: Lin Yang <reaver@flomesh.io>
- Loading branch information
1 parent
f2cb7bd
commit 5ed491c
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
47 changes: 47 additions & 0 deletions
47
charts/fsm/components/scripts/gateways/filters/http/ExternalRateLimit.js
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export default function (config) { | ||
var host = config.externalRateLimit.throttleHost | ||
var passHeaders = config.externalRateLimit.passHeaders | ||
|
||
var $throttleResponse | ||
var $throttleResolve | ||
|
||
var errorResponse = new Message({ status: 503 }, 'Throttle service down') | ||
|
||
return pipeline($=>$ | ||
.fork().to($=>$ | ||
.replaceData() | ||
.replaceMessageStart( | ||
req => { | ||
if (passHeaders instanceof Array && passHeaders.length > 0) { | ||
var head = req.head | ||
var headers = head.headers | ||
var selectedHeaders = Object.fromEntries( | ||
passHeaders.map(k => [k, headers?.[k]]) | ||
) | ||
return new MessageStart({ | ||
method: head.method, | ||
path: head.path, | ||
headers: selectedHeaders, | ||
}) | ||
} else { | ||
return req | ||
} | ||
} | ||
) | ||
.muxHTTP(() => 1, { version: 2 }).to($=>$ | ||
.connect(host) | ||
) | ||
.handleMessage( | ||
res => { | ||
$throttleResponse = res?.head ? res : errorResponse | ||
$throttleResolve(true) | ||
} | ||
) | ||
) | ||
.wait(() => new Promise(r => { $throttleResolve = r })) | ||
.pipe(() => $throttleResponse.head.status === 200 ? 'pass' : 'reject', { | ||
'pass': $=>$.pipeNext(), | ||
'reject': $=>$.replaceData().replaceMessage(() => $throttleResponse) | ||
}) | ||
) | ||
} |
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
14 changes: 14 additions & 0 deletions
14
charts/fsm/components/scripts/gateways/filters/http/RequestTermination.js
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default function (config) { | ||
var abortMessage = new Message( | ||
{ | ||
status: config.requestTermination.response?.status || 503, | ||
headers: config.requestTermination.response?.headers, | ||
}, | ||
config.requestTermination.response?.body || 'Service unavailable' | ||
) | ||
|
||
return pipeline($=>$ | ||
.replaceData() | ||
.replaceMessage(abortMessage) | ||
) | ||
} |