mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-25 16:28:20 +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 (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -102,6 +103,18 @@ func (a *API) SendEndpoint() httprouter.Handle {
|
|||||||
// TODO: Do something with signer?
|
// TODO: Do something with signer?
|
||||||
log.Debugf("request signed by %s", 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?
|
// TODO: Queue up an internal retry and return immediately on failure?
|
||||||
if err := saltyim.Send(req.Endpoint, req.Message, req.Capabilities); err != nil {
|
if err := saltyim.Send(req.Endpoint, req.Message, req.Capabilities); err != nil {
|
||||||
log.WithError(err).Errorf("error sending message to %s", req.Endpoint)
|
log.WithError(err).Errorf("error sending message to %s", req.Endpoint)
|
||||||
|
Loading…
Reference in New Issue
Block a user