Skip to content

Commit

Permalink
fix: p2p scheme ignore for http.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody committed Nov 11, 2024
1 parent c0cc0bc commit 1ba972c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/corehttp/corehttp_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 1ba972c

Please sign in to comment.