Skip to content

Commit

Permalink
fix api path parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulexus committed Jan 10, 2020
1 parent 80d88ee commit e6a61b3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,17 @@ func (s *dispatcherSets) maintain(ctx context.Context) error {
func (s *dispatcherSets) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Handle requests for /check/<setID>/<ip address> to validate membership of an IP to a dispatcher set
if strings.HasPrefix(r.URL.Path, "/check/") {
pieces := strings.Split(r.URL.Path, "/")
if len(pieces) != 3 {
pieces := strings.Split(strings.TrimPrefix(r.URL.Path, "/check/"), "/")
if len(pieces) != 2 {
w.WriteHeader(http.StatusBadRequest)
return
}
setID, err := strconv.Atoi(pieces[1])
setID, err := strconv.Atoi(pieces[0])
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
if s.validateSetMember(setID, pieces[2]) {
if s.validateSetMember(setID, pieces[1]) {
w.WriteHeader(http.StatusOK)
return
}
Expand Down Expand Up @@ -355,6 +355,7 @@ func run() error {
if apiAddr != "" {
var srv http.Server
srv.Addr = apiAddr
srv.Handler = s

go func() {
<-ctx.Done()
Expand Down

0 comments on commit e6a61b3

Please sign in to comment.