Skip to content

Commit dbe2cbc

Browse files
committed
mod: optimize aggregator
1 parent 7b44fc3 commit dbe2cbc

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

internal/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var (
2222
defaultPhishingDb = "https://cfg.rpchub.io/agg/scam-addresses.json"
2323

2424
_Config = &Config{
25-
RequestTimeout: 60,
25+
RequestTimeout: 90,
2626
MaxRetries: 3,
2727
PhishingDb: []string{defaultPhishingDb},
2828
PhishingDbUpdateInterval: 3600,

internal/middleware/plugins/http_proxy.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,21 @@ func (m *HttpProxyMiddleware) OnProcess(session *rpc.Session) error {
109109
m.policiesMap.Set(session.NodeName, policies)
110110
}
111111

112+
// add custom request headers
113+
if strings.Contains(string(ctx.RequestURI()), "coin98.com") {
114+
// bypass coin98 check origin headers
115+
ctx.Request.Header.Set("origin", "https://dex.saros.xyz")
116+
} else {
117+
// TODO: add logic to add custom headers
118+
}
119+
ctx.Request.Header.Set("Accept", "application/json")
120+
ctx.Request.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36")
121+
112122
err := failsafe.Run(func() error {
113123
return m.GetClient(session).Do(&ctx.Request, &ctx.Response)
114124
}, policies...)
115125

116-
// TODO: add response headers
126+
// Add response headers
117127
//if ctx, ok := session.RequestCtx.(*fasthttp.RequestCtx); ok {
118128
// ctx.Response.Header.Set("Access-Control-Max-Age", "86400")
119129
// ctx.Response.Header.Set("Access-Control-Allow-Origin", "*")
@@ -177,7 +187,13 @@ func (m *HttpProxyMiddleware) OnProcess(session *rpc.Session) error {
177187

178188
// check response body
179189
var response map[string]interface{}
180-
if err1 := json.Unmarshal(ctx.Response.Body(), &response); err1 == nil {
190+
if strings.Contains(string(ctx.Response.Body()), "error status code 429") {
191+
log.Error("error response", "node", session.NodeName, "response", string(ctx.Response.Body()))
192+
err = fmt.Errorf("error response %s", string(ctx.Response.Body()))
193+
shouldDisableEndpoint = true
194+
ctx.SetStatusCode(429)
195+
return err
196+
} else if err1 := json.Unmarshal(ctx.Response.Body(), &response); err1 == nil {
181197
if _, ok := response["error"]; ok {
182198
log.Error("error response", "node", session.NodeName, "response", string(ctx.Response.Body()))
183199
err = fmt.Errorf("error response %s", string(ctx.Response.Body()))

0 commit comments

Comments
 (0)