From 1ba972c2cd2d3babc89e7498c8446852c2e778d0 Mon Sep 17 00:00:00 2001 From: cody Date: Mon, 11 Nov 2024 15:51:35 +0800 Subject: [PATCH] fix: p2p scheme ignore for http. --- core/corehttp/corehttp_interceptor.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/corehttp/corehttp_interceptor.go b/core/corehttp/corehttp_interceptor.go index 908f8ffe0..fbf5dc7b3 100644 --- a/core/corehttp/corehttp_interceptor.go +++ b/core/corehttp/corehttp_interceptor.go @@ -63,7 +63,7 @@ func tokenCheckInterceptor(r *http.Request, n *core.IpfsNode) error { return err } apiHost := fmt.Sprint(strings.Split(conf.Addresses.API[0], "/")[2], ":", strings.Split(conf.Addresses.API[0], "/")[4]) - if filterNoNeedTokenCheckReq(r, apiHost) { + if filterNoNeedTokenCheckReq(r, apiHost, conf.Identity.PeerID) { return nil } if !commands.IsLogin { @@ -86,8 +86,8 @@ func tokenCheckInterceptor(r *http.Request, n *core.IpfsNode) error { return nil } -func filterNoNeedTokenCheckReq(r *http.Request, apiHost string) bool { - if filterUrl(r) || filterP2pSchema(r) || filterLocalShellApi(r, apiHost) || filterGatewayUrl(r) { +func filterNoNeedTokenCheckReq(r *http.Request, apiHost string, peerId string) bool { + if filterUrl(r) || filterP2pSchema(r, peerId) || filterLocalShellApi(r, apiHost) || filterGatewayUrl(r) { return true } return false @@ -134,10 +134,13 @@ func filterLocalShellApi(r *http.Request, apiHost string) bool { return false } -func filterP2pSchema(r *http.Request) bool { +func filterP2pSchema(r *http.Request, peerId string) bool { if r.URL.Scheme == "libp2p" { return true } + if r.Host == peerId { + return true + } return false }