Skip to content

Commit

Permalink
build(deps): bump fgw to 1.5.3 (#628)
Browse files Browse the repository at this point in the history
* 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
reaver-flomesh authored Jan 11, 2025
1 parent f2cb7bd commit 5ed491c
Showing 4 changed files with 63 additions and 1 deletion.
Binary file modified charts/fsm/components/scripts.tar.gz
Binary file not shown.
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)
})
)
}
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ export default function (config) {
var interval = Number.parseFloat(config.rateLimit.interval)
var burst = Number.parseInt(config.rateLimit.burst)
var backlog = Number.parseInt(config.rateLimit.backlog)
var blocking = config.rateLimit.blocking === 'true'

var response = new Message(
{
@@ -36,7 +37,7 @@ export default function (config) {
}
}, {
'pass': ($=>$
.throttleMessageRate(rateQuota)
.throttleMessageRate(rateQuota, { blockInput: blocking })
.pipeNext()
.handleMessageStart(() => {
if (backlog) {
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)
)
}

0 comments on commit 5ed491c

Please sign in to comment.