mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-17 13:22:56 +01:00
resolve relative icon and banner urls in nip11 handler.
This commit is contained in:
parent
6e224b9437
commit
7c6031f4e5
@ -126,7 +126,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
websocket.CloseAbnormalClosure, // 1006
|
||||
4537, // some client seems to send many of these
|
||||
) {
|
||||
rl.Log.Printf("unexpected close error from %s: %v\n", r.Header.Get("X-Forwarded-For"), err)
|
||||
rl.Log.Printf("unexpected close error from %s: %v\n", GetIPFromRequest(r), err)
|
||||
}
|
||||
ws.cancel()
|
||||
return
|
||||
|
10
nip11.go
10
nip11.go
@ -3,6 +3,7 @@ package khatru
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request) {
|
||||
@ -20,6 +21,15 @@ func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request) {
|
||||
info.AddSupportedNIP(77)
|
||||
}
|
||||
|
||||
// resolve relative icon and banner URLs against base URL
|
||||
baseURL := rl.getBaseURL(r)
|
||||
if info.Icon != "" && !strings.HasPrefix(info.Icon, "http://") && !strings.HasPrefix(info.Icon, "https://") {
|
||||
info.Icon = strings.TrimSuffix(baseURL, "/") + "/" + strings.TrimPrefix(info.Icon, "/")
|
||||
}
|
||||
if info.Banner != "" && !strings.HasPrefix(info.Banner, "http://") && !strings.HasPrefix(info.Banner, "https://") {
|
||||
info.Banner = strings.TrimSuffix(baseURL, "/") + "/" + strings.TrimPrefix(info.Banner, "/")
|
||||
}
|
||||
|
||||
for _, ovw := range rl.OverwriteRelayInformation {
|
||||
info = ovw(r.Context(), r, info)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user