Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
4d9c7adc
Unverified
Commit
4d9c7adc
authored
Oct 17, 2022
by
mergify[bot]
Committed by
GitHub
Oct 17, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3708 from ethereum-optimism/feat/pattern-origins
proxyd: Support pattern matching in origin and user agent
parents
fd043d83
ca45a85e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
8 deletions
+33
-8
shy-trainers-sneeze.md
.changeset/shy-trainers-sneeze.md
+5
-0
server.go
proxyd/server.go
+28
-8
No files found.
.changeset/shy-trainers-sneeze.md
0 → 100644
View file @
4d9c7adc
---
'
@eth-optimism/proxyd'
:
minor
---
Support pattern matching in exempt origins/user agents
proxyd/server.go
View file @
4d9c7adc
...
...
@@ -8,6 +8,7 @@ import (
"io"
"math"
"net/http"
"regexp"
"strconv"
"strings"
"sync"
...
...
@@ -49,8 +50,8 @@ type Server struct {
upgrader
*
websocket
.
Upgrader
mainLim
FrontendRateLimiter
overrideLims
map
[
string
]
FrontendRateLimiter
limExemptOrigins
map
[
string
]
bool
limExemptUserAgents
map
[
string
]
bool
limExemptOrigins
[]
*
regexp
.
Regexp
limExemptUserAgents
[]
*
regexp
.
Regexp
rpcServer
*
http
.
Server
wsServer
*
http
.
Server
cache
RPCCache
...
...
@@ -104,15 +105,23 @@ func NewServer(
}
var
mainLim
FrontendRateLimiter
limExemptOrigins
:=
make
(
map
[
string
]
bool
)
limExemptUserAgents
:=
make
(
map
[
string
]
bool
)
limExemptOrigins
:=
make
(
[]
*
regexp
.
Regexp
,
0
)
limExemptUserAgents
:=
make
(
[]
*
regexp
.
Regexp
,
0
)
if
rateLimitConfig
.
BaseRate
>
0
{
mainLim
=
limiterFactory
(
time
.
Duration
(
rateLimitConfig
.
BaseInterval
),
rateLimitConfig
.
BaseRate
,
"main"
)
for
_
,
origin
:=
range
rateLimitConfig
.
ExemptOrigins
{
limExemptOrigins
[
strings
.
ToLower
(
origin
)]
=
true
pattern
,
err
:=
regexp
.
Compile
(
origin
)
if
err
!=
nil
{
return
nil
,
err
}
limExemptOrigins
=
append
(
limExemptOrigins
,
pattern
)
}
for
_
,
agent
:=
range
rateLimitConfig
.
ExemptUserAgents
{
limExemptUserAgents
[
strings
.
ToLower
(
agent
)]
=
true
pattern
,
err
:=
regexp
.
Compile
(
agent
)
if
err
!=
nil
{
return
nil
,
err
}
limExemptUserAgents
=
append
(
limExemptUserAgents
,
pattern
)
}
}
else
{
mainLim
=
NoopFrontendRateLimiter
...
...
@@ -548,11 +557,22 @@ func (s *Server) populateContext(w http.ResponseWriter, r *http.Request) context
}
func
(
s
*
Server
)
isUnlimitedOrigin
(
origin
string
)
bool
{
return
s
.
limExemptOrigins
[
strings
.
ToLower
(
origin
)]
for
_
,
pat
:=
range
s
.
limExemptOrigins
{
if
pat
.
MatchString
(
origin
)
{
return
true
}
}
return
false
}
func
(
s
*
Server
)
isUnlimitedUserAgent
(
origin
string
)
bool
{
return
s
.
limExemptUserAgents
[
strings
.
ToLower
(
origin
)]
for
_
,
pat
:=
range
s
.
limExemptUserAgents
{
if
pat
.
MatchString
(
origin
)
{
return
true
}
}
return
false
}
func
setCacheHeader
(
w
http
.
ResponseWriter
,
cached
bool
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment