Skip to content

Commit

Permalink
Merge pull request #451 from bittorrent/feat/dashboard-login
Browse files Browse the repository at this point in the history
feat: get api host from config
  • Loading branch information
mengcody authored Sep 3, 2024
2 parents c337ccd + 64cb083 commit ea22529
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/corehttp/corehttp_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func interceptorAfterResp(r *http.Request, w http.ResponseWriter, n *core.IpfsNo
}

func tokenCheckInterceptor(r *http.Request, n *core.IpfsNode) error {
if filterNoNeedTokenCheckReq(r) {
conf, err := n.Repo.Config()
if err != nil {
return err
}
apiHost := fmt.Sprint(strings.Split(conf.Addresses.API[0], "/")[2], ":", strings.Split(conf.Addresses.API[0], "/")[4])
if filterNoNeedTokenCheckReq(r, apiHost) {
return nil
}
if !commands.IsLogin {
Expand All @@ -81,8 +86,8 @@ func tokenCheckInterceptor(r *http.Request, n *core.IpfsNode) error {
return nil
}

func filterNoNeedTokenCheckReq(r *http.Request) bool {
if filterUrl(r) || filterP2pSchema(r) || filterLocalShellApi(r) || filterGatewayUrl(r) {
func filterNoNeedTokenCheckReq(r *http.Request, apiHost string) bool {
if filterUrl(r) || filterP2pSchema(r) || filterLocalShellApi(r, apiHost) || filterGatewayUrl(r) {
return true
}
return false
Expand Down Expand Up @@ -115,14 +120,14 @@ func filterUrl(r *http.Request) bool {

const (
defaultUserAgent = "Go-http-client/1.1"
cmdUserAget = "go-btfs-cmds/http"
cmdUserAgent = "go-btfs-cmds/http"
)

func filterLocalShellApi(r *http.Request) bool {
func filterLocalShellApi(r *http.Request, apiHost string) bool {
host := r.Host
ua := r.Header.Get("User-Agent")
// ua is not Go-http-client
if host == "127.0.0.1:5001" && (ua == defaultUserAgent || ua == cmdUserAget) {
if host == apiHost && (ua == defaultUserAgent || ua == cmdUserAgent) {
return true
}
return false
Expand Down

0 comments on commit ea22529

Please sign in to comment.