Compare commits

..

2 Commits

Author SHA1 Message Date
4ef5b7b2dd Topic and callback should be absolute urls
All checks were successful
continuous-integration/drone/push Build is passing
2019-03-20 00:00:00 +01:00
72d161add4 Add unique index for topic and callback 2019-03-19 23:39:05 +01:00
3 changed files with 14 additions and 6 deletions

View File

@ -154,16 +154,23 @@ func (handler *subscriptionHandler) handleSubscription(w http.ResponseWriter, r
callbackURL, err := url.Parse(callback)
if callback == "" || err != nil {
http.Error(w, "Can not parse callback url", 400)
log.Printf("Can not parse callback url: %s\n", callback)
http.Error(w, "cannot parse callback url", 400)
log.Printf("cannot parse callback url: %s", callback)
return err
}
if !callbackURL.IsAbs() {
http.Error(w, "callback url is not absolute", 400)
return fmt.Errorf("callback url is not absolute: %s", callback)
}
topicURL, err := url.Parse(topic)
if topic == "" || err != nil {
http.Error(w, "Can't parse topic url", 400)
log.Printf("Can't parse topic url: %s\n", topic)
return err
http.Error(w, "cannot parse topic url", 400)
return fmt.Errorf("cannot parse topic url: %s\n", topic)
}
if !topicURL.IsAbs() {
http.Error(w, "topic url is not absolute", 400)
return fmt.Errorf("topic url is not absolute: %s", topic)
}
log.Println("subscribe: sending 202 header request accepted")

View File

@ -1,4 +1,4 @@
create table "subscribers"
CREATE TABLE IF NOT EXISTS "subscribers"
(
id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
topic varchar(255) not null,

1
db/02_unique.sql Normal file
View File

@ -0,0 +1 @@
CREATE UNIQUE INDEX IF NOT EXISTS "subscribers_topic_callback" ON "subscribers" ("topic", "callback");