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 < 200 || respCode >= 300 {
|
||||||
if respCode == 410 {
|
if respCode == 410 {
|
||||||
// Delete mention, because source is gone
|
// Delete mention, because source is gone
|
||||||
// TODO: Implement deleteion
|
// TODO: Implement deletion
|
||||||
w.Header().Add("Location", targetUrl.String())
|
returnSuccess(targetUrl.String(), w, r)
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
err = errors.New("source returned error")
|
err = errors.New("source returned error")
|
||||||
|
@ -130,13 +129,7 @@ func HandleWebmention(w http.ResponseWriter, r *http.Request) {
|
||||||
_, _ = w.Write([]byte(err.Error()))
|
_, _ = w.Write([]byte(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Add("Location", targetUrl.String())
|
returnSuccess(targetUrl.String(), w, r)
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
// Purge BunnyCDN in 10 seconds
|
|
||||||
go func() {
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
Purge(targetUrl.String())
|
|
||||||
}()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,3 +165,19 @@ func saveWebmention(mention *Mention) (err error) {
|
||||||
err = UpdateFile(filePath, string(bytesRepresentation), "New webmention from "+mention.Source)
|
err = UpdateFile(filePath, string(bytesRepresentation), "New webmention from "+mention.Source)
|
||||||
return
|
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