mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-16 11:58:24 +00:00
Fix handling for bad endpoints from mixbehaving clients proxying send requests (#163)
Co-authored-by: James Mills <prologic@shortcircuit.net.au> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/163 Reviewed-by: xuu <xuu@noreply@mills.io>
This commit is contained in:
parent
823c112547
commit
994895681d
@ -2,6 +2,7 @@ package internal
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -102,6 +103,18 @@ func (a *API) SendEndpoint() httprouter.Handle {
|
||||
// TODO: Do something with signer?
|
||||
log.Debugf("request signed by %s", signer)
|
||||
|
||||
u, err := url.Parse(req.Endpoint)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("error parsing endpoing %s", req.Endpoint)
|
||||
http.Error(w, "Bad Endpoint", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if !u.IsAbs() {
|
||||
log.Errorf("endpoint %s is not an absolute uri", req.Endpoint)
|
||||
http.Error(w, "Bad Endpoint", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Queue up an internal retry and return immediately on failure?
|
||||
if err := saltyim.Send(req.Endpoint, req.Message, req.Capabilities); err != nil {
|
||||
log.WithError(err).Errorf("error sending message to %s", req.Endpoint)
|
||||
|
Loading…
Reference in New Issue
Block a user