Skip to content

Commit

Permalink
optimize(test url): determine the correct status code based on the path
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 committed Sep 27, 2022
1 parent e3135ab commit 4f03bfa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"gopkg.in/yaml.v3"
"net"
"net/http"
"path"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -72,7 +75,10 @@ func (d *Dialer) Test(ctx context.Context, url string) (bool, error) {
return false, fmt.Errorf("%v: %w", ConnectivityTestFailedErr, err)
}
defer resp.Body.Close()
return resp.StatusCode == 204, nil
if page := path.Base(req.URL.Path); strings.HasPrefix(page, "generate_") {
return strconv.Itoa(resp.StatusCode) == strings.TrimPrefix(page, "generate_"), nil
}
return resp.StatusCode >= 200 && resp.StatusCode < 400, nil
}

type FromLinkCreator func(link string) (dialer *Dialer, err error)
Expand Down

0 comments on commit 4f03bfa

Please sign in to comment.