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
3c2926b1
Commit
3c2926b1
authored
Jan 25, 2022
by
inphi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/proxyd: Add debug cache status header to HTTP responses
parent
d064eb8e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
slimy-sheep-smell.md
.changeset/slimy-sheep-smell.md
+5
-0
server.go
go/proxyd/server.go
+20
-8
No files found.
.changeset/slimy-sheep-smell.md
0 → 100644
View file @
3c2926b1
---
'
@eth-optimism/proxyd'
:
minor
---
Add debug cache status header to proxyd responses
go/proxyd/server.go
View file @
3c2926b1
...
...
@@ -159,6 +159,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
}
batchRes
:=
make
([]
*
RPCRes
,
len
(
reqs
),
len
(
reqs
))
var
cached
bool
for
i
:=
0
;
i
<
len
(
reqs
);
i
++
{
req
,
err
:=
ParseRPCReq
(
reqs
[
i
])
if
err
!=
nil
{
...
...
@@ -167,9 +168,10 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
continue
}
batchRes
[
i
]
=
s
.
handleSingleRPC
(
ctx
,
req
)
batchRes
[
i
]
,
cached
=
s
.
handleSingleRPC
(
ctx
,
req
)
}
setCacheHeader
(
w
,
cached
)
writeBatchRPCRes
(
ctx
,
w
,
batchRes
)
return
}
...
...
@@ -181,14 +183,15 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
return
}
backendRes
:=
s
.
handleSingleRPC
(
ctx
,
req
)
backendRes
,
cached
:=
s
.
handleSingleRPC
(
ctx
,
req
)
setCacheHeader
(
w
,
cached
)
writeRPCRes
(
ctx
,
w
,
backendRes
)
}
func
(
s
*
Server
)
handleSingleRPC
(
ctx
context
.
Context
,
req
*
RPCReq
)
*
RPCRes
{
func
(
s
*
Server
)
handleSingleRPC
(
ctx
context
.
Context
,
req
*
RPCReq
)
(
*
RPCRes
,
bool
)
{
if
err
:=
ValidateRPCReq
(
req
);
err
!=
nil
{
RecordRPCError
(
ctx
,
BackendProxyd
,
MethodUnknown
,
err
)
return
NewRPCErrorRes
(
nil
,
err
)
return
NewRPCErrorRes
(
nil
,
err
)
,
false
}
group
:=
s
.
rpcMethodMappings
[
req
.
Method
]
...
...
@@ -202,7 +205,7 @@ func (s *Server) handleSingleRPC(ctx context.Context, req *RPCReq) *RPCRes {
"method"
,
req
.
Method
,
)
RecordRPCError
(
ctx
,
BackendProxyd
,
MethodUnknown
,
ErrMethodNotWhitelisted
)
return
NewRPCErrorRes
(
req
.
ID
,
ErrMethodNotWhitelisted
)
return
NewRPCErrorRes
(
req
.
ID
,
ErrMethodNotWhitelisted
)
,
false
}
var
backendRes
*
RPCRes
...
...
@@ -215,7 +218,7 @@ func (s *Server) handleSingleRPC(ctx context.Context, req *RPCReq) *RPCRes {
)
}
if
backendRes
!=
nil
{
return
backendRes
return
backendRes
,
true
}
backendRes
,
err
=
s
.
backendGroups
[
group
]
.
Forward
(
ctx
,
req
)
...
...
@@ -226,7 +229,7 @@ func (s *Server) handleSingleRPC(ctx context.Context, req *RPCReq) *RPCRes {
"req_id"
,
GetReqID
(
ctx
),
"err"
,
err
,
)
return
NewRPCErrorRes
(
req
.
ID
,
err
)
return
NewRPCErrorRes
(
req
.
ID
,
err
)
,
false
}
if
backendRes
.
Error
==
nil
{
...
...
@@ -239,7 +242,7 @@ func (s *Server) handleSingleRPC(ctx context.Context, req *RPCReq) *RPCRes {
}
}
return
backendRes
return
backendRes
,
false
}
func
(
s
*
Server
)
HandleWS
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -322,6 +325,15 @@ func (s *Server) populateContext(w http.ResponseWriter, r *http.Request) context
)
}
func
setCacheHeader
(
w
http
.
ResponseWriter
,
cached
bool
)
{
const
cacheStatusHdr
=
"X-Proxyd-Cache-Status"
if
cached
{
w
.
Header
()
.
Set
(
cacheStatusHdr
,
"HIT"
)
}
else
{
w
.
Header
()
.
Set
(
cacheStatusHdr
,
"MISS"
)
}
}
func
writeRPCError
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
id
json
.
RawMessage
,
err
error
)
{
var
res
*
RPCRes
if
r
,
ok
:=
err
.
(
*
RPCErr
);
ok
{
...
...
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