Skip to content

Commit 9643d5e

Browse files
authored
extract url into the context in jsonrpcserver (#59)
Sometimes we need to access some of the url params that influence execution logic
1 parent d57b32b commit 9643d5e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

rpcserver/jsonrpc_server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"io"
1313
"log/slog"
1414
"net/http"
15+
"net/url"
1516
"strconv"
1617
"strings"
1718
"time"
@@ -52,6 +53,7 @@ type (
5253
highPriorityKey struct{}
5354
builderNetSentAtKey struct{}
5455
signerKey struct{}
56+
urlKey struct{}
5557
originKey struct{}
5658
sizeKey struct{}
5759
)
@@ -267,6 +269,8 @@ func (h *JSONRPCHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
267269
}
268270
ctx = context.WithValue(ctx, signerKey{}, signer)
269271
}
272+
// r.URL
273+
ctx = context.WithValue(ctx, urlKey{}, r.URL)
270274

271275
// read request
272276
var req jsonRPCRequest
@@ -417,3 +421,7 @@ func GetOrigin(ctx context.Context) string {
417421
func GetRequestSize(ctx context.Context) int {
418422
return ctx.Value(sizeKey{}).(int)
419423
}
424+
425+
func GetURL(ctx context.Context) *url.URL {
426+
return ctx.Value(urlKey{}).(*url.URL)
427+
}

0 commit comments

Comments
 (0)