Fix error in unsubscriber
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- wrong error checking
This commit is contained in:
parent
59668090df
commit
071bf66721
|
@ -87,38 +87,47 @@ func (handler *subscriptionHandler) handleUnsubscription(w http.ResponseWriter,
|
|||
topic := r.Form.Get("hub.topic")
|
||||
mode := r.Form.Get("hub.mode")
|
||||
|
||||
if subscribers, err := handler.store.Subscribers(topic); err != nil {
|
||||
for _, subscriber := range subscribers {
|
||||
if subscriber.Callback != callback {
|
||||
continue
|
||||
}
|
||||
ourChallenge := randStringBytes(12)
|
||||
subscribers, err := handler.store.Subscribers(topic)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get subscribers for %s", topic)
|
||||
}
|
||||
|
||||
validationURL, err := url.Parse(callback)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
q := validationURL.Query()
|
||||
q.Add("hub.mode", mode)
|
||||
q.Add("hub.topic", topic)
|
||||
q.Add("hub.challenge", ourChallenge)
|
||||
validationURL.RawQuery = q.Encode()
|
||||
if validateURL(validationURL.String(), ourChallenge) {
|
||||
err = handler.store.Unsubscribe(topic, callback)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
found := false
|
||||
for _, subscriber := range subscribers {
|
||||
if subscriber.Callback != callback {
|
||||
continue
|
||||
}
|
||||
|
||||
w.WriteHeader(200)
|
||||
found = true
|
||||
|
||||
ourChallenge := randStringBytes(12)
|
||||
|
||||
validationURL, err := url.Parse(callback)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
q := validationURL.Query()
|
||||
q.Add("hub.mode", mode)
|
||||
q.Add("hub.topic", topic)
|
||||
q.Add("hub.challenge", ourChallenge)
|
||||
validationURL.RawQuery = q.Encode()
|
||||
if validateURL(validationURL.String(), ourChallenge) {
|
||||
err = handler.store.Unsubscribe(topic, callback)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteHeader(200)
|
||||
if found {
|
||||
_, err = fmt.Fprintf(w, "Unsubscribed\n")
|
||||
return err
|
||||
} else {
|
||||
http.Error(w, "Hub does not handle subscription for topic", 400)
|
||||
}
|
||||
return nil
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (handler *subscriptionHandler) handleSubscription(w http.ResponseWriter, r *http.Request) error {
|
||||
|
|
Loading…
Reference in New Issue
Block a user