Skip to content

Commit 1039fa5

Browse files
committed
mod: whitelist headers for chain
1 parent da0811c commit 1039fa5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

internal/middleware/plugins/http_proxy.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727

2828
var DISABLED_NODE_STATUS_CODES = []int{401, 403, 502}
2929

30+
var WHITELIST_CHAINS = []string{"sui", "solana", "solana_das", "solana_das_2"}
31+
3032
type HttpProxyMiddleware struct {
3133
nextMiddleware middleware.Middleware
3234
enabled bool
@@ -187,19 +189,21 @@ func (m *HttpProxyMiddleware) OnProcess(session *rpc.Session) error {
187189
return err
188190
}
189191

190-
// check response header
191-
contentType := ctx.Response.Header.Peek("Content-Type")
192-
if !strings.Contains(string(contentType), "application/json") {
193-
log.Error("invalid response content type", contentType, "node", session.NodeName)
194-
err = fmt.Errorf("invalid response content type %s", contentType)
195-
shouldDisableEndpoint = true
196-
now := time.Now().UnixMilli()
197-
_, ok := m.disableEndpoints.Get(session.NodeName)
198-
if !ok {
199-
m.disableEndpoints.Set(session.NodeName, now)
192+
if !slices.Contains(WHITELIST_CHAINS, session.Chain) {
193+
// check response header
194+
contentType := ctx.Response.Header.Peek("Content-Type")
195+
if !strings.Contains(string(contentType), "application/json") {
196+
log.Error("invalid response content type", contentType, "node", session.NodeName)
197+
err = fmt.Errorf("invalid response content type %s", contentType)
198+
shouldDisableEndpoint = true
199+
now := time.Now().UnixMilli()
200+
_, ok := m.disableEndpoints.Get(session.NodeName)
201+
if !ok {
202+
m.disableEndpoints.Set(session.NodeName, now)
203+
}
204+
ctx.SetStatusCode(500)
205+
return err
200206
}
201-
ctx.SetStatusCode(500)
202-
return err
203207
}
204208

205209
// check response body

0 commit comments

Comments
 (0)