2021-04-07 11:29:21 +02:00
|
|
|
|
|
|
|
package webmention
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2021-04-07 11:44:58 +02:00
|
|
|
"fmt"
|
2021-04-07 11:29:21 +02:00
|
|
|
|
|
|
|
"github.com/wgroeneveld/go-jamming/common"
|
2021-04-08 09:54:47 +02:00
|
|
|
"github.com/wgroeneveld/go-jamming/rest"
|
2021-04-07 11:29:21 +02:00
|
|
|
)
|
|
|
|
|
2021-04-07 11:44:58 +02:00
|
|
|
func HandleGet(conf *common.Config) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Println("handling get")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func HandlePut(conf *common.Config) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Println("handling put")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func HandlePost(conf *common.Config) http.HandlerFunc {
|
2021-04-08 09:54:47 +02:00
|
|
|
httpClient := &rest.HttpClient{}
|
|
|
|
|
2021-04-07 11:29:21 +02:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2021-04-07 15:22:24 +02:00
|
|
|
r.ParseForm()
|
|
|
|
if !validate(r, r.Header, conf) {
|
2021-04-08 09:54:47 +02:00
|
|
|
rest.BadRequest(w)
|
2021-04-07 17:31:23 +02:00
|
|
|
return
|
2021-04-07 15:22:24 +02:00
|
|
|
}
|
2021-04-07 17:31:23 +02:00
|
|
|
|
|
|
|
target := r.FormValue("target")
|
2021-04-08 09:54:47 +02:00
|
|
|
if !isValidTargetUrl(target, httpClient) {
|
|
|
|
rest.BadRequest(w)
|
2021-04-07 17:31:23 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-09 12:40:37 +02:00
|
|
|
wm := Mention{
|
|
|
|
Source: r.FormValue("source"),
|
|
|
|
Target: target,
|
2021-04-08 09:54:47 +02:00
|
|
|
}
|
2021-04-09 12:40:37 +02:00
|
|
|
recv := &Receiver{
|
|
|
|
RestClient: httpClient,
|
|
|
|
Conf: conf,
|
2021-04-08 09:54:47 +02:00
|
|
|
}
|
2021-04-07 17:31:23 +02:00
|
|
|
|
2021-04-09 12:40:37 +02:00
|
|
|
go recv.Receive(wm)
|
2021-04-08 09:54:47 +02:00
|
|
|
rest.Accept(w)
|
2021-04-07 11:29:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|