Fix redirection on success when sending webmention
parent
88c17bacb8
commit
988ff42365
|
@ -101,9 +101,8 @@ func HandleWebmention(w http.ResponseWriter, r *http.Request) {
|
|||
if respCode < 200 || respCode >= 300 {
|
||||
if respCode == 410 {
|
||||
// Delete mention, because source is gone
|
||||
// TODO: Implement deleteion
|
||||
w.Header().Add("Location", targetUrl.String())
|
||||
w.WriteHeader(http.StatusOK)
|
||||
// TODO: Implement deletion
|
||||
returnSuccess(targetUrl.String(), w, r)
|
||||
return
|
||||
} else {
|
||||
err = errors.New("source returned error")
|
||||
|
@ -130,13 +129,7 @@ func HandleWebmention(w http.ResponseWriter, r *http.Request) {
|
|||
_, _ = w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Header().Add("Location", targetUrl.String())
|
||||
w.WriteHeader(http.StatusOK)
|
||||
// Purge BunnyCDN in 10 seconds
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
Purge(targetUrl.String())
|
||||
}()
|
||||
returnSuccess(targetUrl.String(), w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -172,3 +165,19 @@ func saveWebmention(mention *Mention) (err error) {
|
|||
err = UpdateFile(filePath, string(bytesRepresentation), "New webmention from "+mention.Source)
|
||||
return
|
||||
}
|
||||
|
||||
func returnSuccess(target string, w http.ResponseWriter, r *http.Request) {
|
||||
if strings.Contains(r.Header.Get("Accept"), "text/html") {
|
||||
// Redirect browser
|
||||
w.Header().Add("Location", target)
|
||||
w.WriteHeader(http.StatusSeeOther)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
// Purge BunnyCDN in 10 seconds
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
Purge(target)
|
||||
}()
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue