mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-05-17 19:03:29 +12:00
use existing message and title fields for templates
This commit is contained in:
parent
df7d6baec5
commit
b2eb5b94bd
|
@ -739,7 +739,7 @@ func (s *Server) handlePublishInternal(r *http.Request, v *visitor) (*message, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m := newDefaultMessage(t.ID, "")
|
m := newDefaultMessage(t.ID, "")
|
||||||
cache, firebase, email, call, messageTemplate, titleTemplate, unifiedpush, e := s.parsePublishParams(r, m)
|
cache, firebase, email, call, template, unifiedpush, e := s.parsePublishParams(r, m)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e.With(t)
|
return nil, e.With(t)
|
||||||
}
|
}
|
||||||
|
@ -770,7 +770,7 @@ func (s *Server) handlePublishInternal(r *http.Request, v *visitor) (*message, e
|
||||||
if cache {
|
if cache {
|
||||||
m.Expires = time.Unix(m.Time, 0).Add(v.Limits().MessageExpiryDuration).Unix()
|
m.Expires = time.Unix(m.Time, 0).Add(v.Limits().MessageExpiryDuration).Unix()
|
||||||
}
|
}
|
||||||
if err := s.handlePublishBody(r, v, m, body, messageTemplate, titleTemplate, unifiedpush); err != nil {
|
if err := s.handlePublishBody(r, v, m, body, template, unifiedpush); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if m.Message == "" {
|
if m.Message == "" {
|
||||||
|
@ -925,7 +925,7 @@ func (s *Server) forwardPollRequest(v *visitor, m *message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, firebase bool, email, call string, messageTemplate string, titleTemplate string, unifiedpush bool, err *errHTTP) {
|
func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, firebase bool, email, call string, template bool, unifiedpush bool, err *errHTTP) {
|
||||||
cache = readBoolParam(r, true, "x-cache", "cache")
|
cache = readBoolParam(r, true, "x-cache", "cache")
|
||||||
firebase = readBoolParam(r, true, "x-firebase", "firebase")
|
firebase = readBoolParam(r, true, "x-firebase", "firebase")
|
||||||
m.Title = readParam(r, "x-title", "title", "t")
|
m.Title = readParam(r, "x-title", "title", "t")
|
||||||
|
@ -941,7 +941,7 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi
|
||||||
}
|
}
|
||||||
if attach != "" {
|
if attach != "" {
|
||||||
if !urlRegex.MatchString(attach) {
|
if !urlRegex.MatchString(attach) {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestAttachmentURLInvalid
|
return false, false, "", "", false, false, errHTTPBadRequestAttachmentURLInvalid
|
||||||
}
|
}
|
||||||
m.Attachment.URL = attach
|
m.Attachment.URL = attach
|
||||||
if m.Attachment.Name == "" {
|
if m.Attachment.Name == "" {
|
||||||
|
@ -959,20 +959,20 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi
|
||||||
}
|
}
|
||||||
if icon != "" {
|
if icon != "" {
|
||||||
if !urlRegex.MatchString(icon) {
|
if !urlRegex.MatchString(icon) {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestIconURLInvalid
|
return false, false, "", "", false, false, errHTTPBadRequestIconURLInvalid
|
||||||
}
|
}
|
||||||
m.Icon = icon
|
m.Icon = icon
|
||||||
}
|
}
|
||||||
email = readParam(r, "x-email", "x-e-mail", "email", "e-mail", "mail", "e")
|
email = readParam(r, "x-email", "x-e-mail", "email", "e-mail", "mail", "e")
|
||||||
if s.smtpSender == nil && email != "" {
|
if s.smtpSender == nil && email != "" {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestEmailDisabled
|
return false, false, "", "", false, false, errHTTPBadRequestEmailDisabled
|
||||||
}
|
}
|
||||||
call = readParam(r, "x-call", "call")
|
call = readParam(r, "x-call", "call")
|
||||||
if call != "" && (s.config.TwilioAccount == "" || s.userManager == nil) {
|
if call != "" && (s.config.TwilioAccount == "" || s.userManager == nil) {
|
||||||
print("call: %s", call)
|
print("call: %s", call)
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestPhoneCallsDisabled
|
return false, false, "", "", false, false, errHTTPBadRequestPhoneCallsDisabled
|
||||||
} else if call != "" && !isBoolValue(call) && !phoneNumberRegex.MatchString(call) {
|
} else if call != "" && !isBoolValue(call) && !phoneNumberRegex.MatchString(call) {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestPhoneNumberInvalid
|
return false, false, "", "", false, false, errHTTPBadRequestPhoneNumberInvalid
|
||||||
}
|
}
|
||||||
messageStr := strings.ReplaceAll(readParam(r, "x-message", "message", "m"), "\\n", "\n")
|
messageStr := strings.ReplaceAll(readParam(r, "x-message", "message", "m"), "\\n", "\n")
|
||||||
if messageStr != "" {
|
if messageStr != "" {
|
||||||
|
@ -981,27 +981,27 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi
|
||||||
var e error
|
var e error
|
||||||
m.Priority, e = util.ParsePriority(readParam(r, "x-priority", "priority", "prio", "p"))
|
m.Priority, e = util.ParsePriority(readParam(r, "x-priority", "priority", "prio", "p"))
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestPriorityInvalid
|
return false, false, "", "", false, false, errHTTPBadRequestPriorityInvalid
|
||||||
}
|
}
|
||||||
m.Tags = readCommaSeparatedParam(r, "x-tags", "tags", "tag", "ta")
|
m.Tags = readCommaSeparatedParam(r, "x-tags", "tags", "tag", "ta")
|
||||||
delayStr := readParam(r, "x-delay", "delay", "x-at", "at", "x-in", "in")
|
delayStr := readParam(r, "x-delay", "delay", "x-at", "at", "x-in", "in")
|
||||||
if delayStr != "" {
|
if delayStr != "" {
|
||||||
if !cache {
|
if !cache {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestDelayNoCache
|
return false, false, "", "", false, false, errHTTPBadRequestDelayNoCache
|
||||||
}
|
}
|
||||||
if email != "" {
|
if email != "" {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestDelayNoEmail // we cannot store the email address (yet)
|
return false, false, "", "", false, false, errHTTPBadRequestDelayNoEmail // we cannot store the email address (yet)
|
||||||
}
|
}
|
||||||
if call != "" {
|
if call != "" {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestDelayNoCall // we cannot store the phone number (yet)
|
return false, false, "", "", false, false, errHTTPBadRequestDelayNoCall // we cannot store the phone number (yet)
|
||||||
}
|
}
|
||||||
delay, err := util.ParseFutureTime(delayStr, time.Now())
|
delay, err := util.ParseFutureTime(delayStr, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestDelayCannotParse
|
return false, false, "", "", false, false, errHTTPBadRequestDelayCannotParse
|
||||||
} else if delay.Unix() < time.Now().Add(s.config.MessageDelayMin).Unix() {
|
} else if delay.Unix() < time.Now().Add(s.config.MessageDelayMin).Unix() {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestDelayTooSmall
|
return false, false, "", "", false, false, errHTTPBadRequestDelayTooSmall
|
||||||
} else if delay.Unix() > time.Now().Add(s.config.MessageDelayMax).Unix() {
|
} else if delay.Unix() > time.Now().Add(s.config.MessageDelayMax).Unix() {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestDelayTooLarge
|
return false, false, "", "", false, false, errHTTPBadRequestDelayTooLarge
|
||||||
}
|
}
|
||||||
m.Time = delay.Unix()
|
m.Time = delay.Unix()
|
||||||
}
|
}
|
||||||
|
@ -1009,15 +1009,14 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi
|
||||||
if actionsStr != "" {
|
if actionsStr != "" {
|
||||||
m.Actions, e = parseActions(actionsStr)
|
m.Actions, e = parseActions(actionsStr)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return false, false, "", "", "", "", false, errHTTPBadRequestActionsInvalid.Wrap(e.Error())
|
return false, false, "", "", false, false, errHTTPBadRequestActionsInvalid.Wrap(e.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contentType, markdown := readParam(r, "content-type", "content_type"), readBoolParam(r, false, "x-markdown", "markdown", "md")
|
contentType, markdown := readParam(r, "content-type", "content_type"), readBoolParam(r, false, "x-markdown", "markdown", "md")
|
||||||
if markdown || strings.ToLower(contentType) == "text/markdown" {
|
if markdown || strings.ToLower(contentType) == "text/markdown" {
|
||||||
m.ContentType = "text/markdown"
|
m.ContentType = "text/markdown"
|
||||||
}
|
}
|
||||||
messageTemplate = readParam(r, "x-template-message", "template-message", "tpl-m")
|
template = readBoolParam(r, false, "x-template", "template", "tpl")
|
||||||
titleTemplate = readParam(r, "x-template-title", "template-title", "tpl-t")
|
|
||||||
unifiedpush = readBoolParam(r, false, "x-unifiedpush", "unifiedpush", "up") // see GET too!
|
unifiedpush = readBoolParam(r, false, "x-unifiedpush", "unifiedpush", "up") // see GET too!
|
||||||
if unifiedpush {
|
if unifiedpush {
|
||||||
firebase = false
|
firebase = false
|
||||||
|
@ -1029,7 +1028,7 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi
|
||||||
cache = false
|
cache = false
|
||||||
email = ""
|
email = ""
|
||||||
}
|
}
|
||||||
return cache, firebase, email, call, messageTemplate, titleTemplate, unifiedpush, nil
|
return cache, firebase, email, call, template, unifiedpush, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlePublishBody consumes the PUT/POST body and decides whether the body is an attachment or the message.
|
// handlePublishBody consumes the PUT/POST body and decides whether the body is an attachment or the message.
|
||||||
|
@ -1046,17 +1045,17 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi
|
||||||
// If file.txt is <= 4096 (message limit) and valid UTF-8, treat it as a message
|
// If file.txt is <= 4096 (message limit) and valid UTF-8, treat it as a message
|
||||||
// 6. curl -T file.txt ntfy.sh/mytopic
|
// 6. curl -T file.txt ntfy.sh/mytopic
|
||||||
// If file.txt is > message limit, treat it as an attachment
|
// If file.txt is > message limit, treat it as an attachment
|
||||||
func (s *Server) handlePublishBody(r *http.Request, v *visitor, m *message, body *util.PeekedReadCloser, messageTemplate string, titleTemplate string, unifiedpush bool) error {
|
func (s *Server) handlePublishBody(r *http.Request, v *visitor, m *message, body *util.PeekedReadCloser, template bool, unifiedpush bool) error {
|
||||||
if m.Event == pollRequestEvent { // Case 1
|
if m.Event == pollRequestEvent { // Case 1
|
||||||
return s.handleBodyDiscard(body)
|
return s.handleBodyDiscard(body)
|
||||||
} else if unifiedpush {
|
} else if unifiedpush {
|
||||||
return s.handleBodyAsMessageAutoDetect(m, body) // Case 2
|
return s.handleBodyAsMessageAutoDetect(m, body) // Case 2
|
||||||
} else if m.Attachment != nil && m.Attachment.URL != "" {
|
} else if m.Attachment != nil && m.Attachment.URL != "" {
|
||||||
return s.handleBodyAsTextMessage(m, body, messageTemplate, titleTemplate) // Case 3
|
return s.handleBodyAsTextMessage(m, body, template) // Case 3
|
||||||
} else if m.Attachment != nil && m.Attachment.Name != "" {
|
} else if m.Attachment != nil && m.Attachment.Name != "" {
|
||||||
return s.handleBodyAsAttachment(r, v, m, body) // Case 4
|
return s.handleBodyAsAttachment(r, v, m, body) // Case 4
|
||||||
} else if !body.LimitReached && utf8.Valid(body.PeekedBytes) {
|
} else if !body.LimitReached && utf8.Valid(body.PeekedBytes) {
|
||||||
return s.handleBodyAsTextMessage(m, body, messageTemplate, titleTemplate) // Case 5
|
return s.handleBodyAsTextMessage(m, body, template) // Case 5
|
||||||
}
|
}
|
||||||
return s.handleBodyAsAttachment(r, v, m, body) // Case 6
|
return s.handleBodyAsAttachment(r, v, m, body) // Case 6
|
||||||
}
|
}
|
||||||
|
@ -1077,39 +1076,36 @@ func (s *Server) handleBodyAsMessageAutoDetect(m *message, body *util.PeekedRead
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleBodyAsTextMessage(m *message, body *util.PeekedReadCloser, messageTemplate string, titleTemplate string) error {
|
func (s *Server) handleBodyAsTextMessage(m *message, body *util.PeekedReadCloser, template bool) error {
|
||||||
if !utf8.Valid(body.PeekedBytes) {
|
if !utf8.Valid(body.PeekedBytes) {
|
||||||
return errHTTPBadRequestMessageNotUTF8.With(m)
|
return errHTTPBadRequestMessageNotUTF8.With(m)
|
||||||
}
|
}
|
||||||
if len(body.PeekedBytes) > 0 { // Empty body should not override message (publish via GET!)
|
if len(body.PeekedBytes) > 0 { // Empty body should not override message (publish via GET!)
|
||||||
peakedBody := strings.TrimSpace(string(body.PeekedBytes)) // Truncates the message to the peek limit if required
|
peakedBody := strings.TrimSpace(string(body.PeekedBytes)) // Truncates the message to the peek limit if required
|
||||||
// Replace JSON paths in messageTemplate
|
if template && gjson.Valid(peakedBody) {
|
||||||
if messageTemplate != "" && gjson.Valid(peakedBody) {
|
// Replace JSON paths in message
|
||||||
m.Message = messageTemplate
|
|
||||||
r := regexp.MustCompile(`\${([^}]+)}`)
|
r := regexp.MustCompile(`\${([^}]+)}`)
|
||||||
messageMatches := r.FindAllStringSubmatch(messageTemplate, -1)
|
matches := r.FindAllStringSubmatch(m.Message, -1)
|
||||||
for _, v := range messageMatches {
|
for _, v := range matches {
|
||||||
query := v[1]
|
query := v[1]
|
||||||
result := gjson.Get(peakedBody, query)
|
result := gjson.Get(peakedBody, query)
|
||||||
if result.Exists() {
|
if result.Exists() {
|
||||||
m.Message = strings.ReplaceAll(m.Message, fmt.Sprintf("${%s}", query), result.String())
|
m.Message = strings.ReplaceAll(m.Message, fmt.Sprintf("${%s}", query), result.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
m.Message = peakedBody
|
// Replace JSON paths in title
|
||||||
}
|
r = regexp.MustCompile(`\${([^}]+)}`)
|
||||||
// Replace JSON paths in titleTemplate
|
matches = r.FindAllStringSubmatch(m.Title, -1)
|
||||||
if titleTemplate != "" && gjson.Valid(peakedBody) {
|
for _, v := range matches {
|
||||||
m.Title = titleTemplate
|
|
||||||
r := regexp.MustCompile(`\${([^}]+)}`)
|
|
||||||
titleMatches := r.FindAllStringSubmatch(titleTemplate, -1)
|
|
||||||
for _, v := range titleMatches {
|
|
||||||
query := v[1]
|
query := v[1]
|
||||||
result := gjson.Get(peakedBody, query)
|
result := gjson.Get(peakedBody, query)
|
||||||
if result.Exists() {
|
if result.Exists() {
|
||||||
m.Title = strings.ReplaceAll(m.Title, fmt.Sprintf("${%s}", query), result.String())
|
m.Title = strings.ReplaceAll(m.Title, fmt.Sprintf("${%s}", query), result.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
m.Message = peakedBody
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if m.Attachment != nil && m.Attachment.Name != "" && m.Message == "" {
|
if m.Attachment != nil && m.Attachment.Name != "" && m.Message == "" {
|
||||||
|
|
|
@ -2628,8 +2628,9 @@ func TestServer_UpstreamBaseURL_DoNotForwardUnifiedPush(t *testing.T) {
|
||||||
func TestServer_MessageTemplate(t *testing.T) {
|
func TestServer_MessageTemplate(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here"}}`, map[string]string{
|
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here"}}`, map[string]string{
|
||||||
"X-Template-Message": "${foo}",
|
"X-Message": "${foo}",
|
||||||
"X-Template-Title": "${nested.title}",
|
"X-Title": "${nested.title}",
|
||||||
|
"X-Template": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code)
|
require.Equal(t, 200, response.Code)
|
||||||
|
@ -2641,8 +2642,9 @@ func TestServer_MessageTemplate(t *testing.T) {
|
||||||
func TestServer_MessageTemplate_RepeatPlaceholder(t *testing.T) {
|
func TestServer_MessageTemplate_RepeatPlaceholder(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here"}}`, map[string]string{
|
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here"}}`, map[string]string{
|
||||||
"Template-Message": "${foo} is ${foo}",
|
"Message": "${foo} is ${foo}",
|
||||||
"Template-Title": "${nested.title} is ${nested.title}",
|
"Title": "${nested.title} is ${nested.title}",
|
||||||
|
"Template": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code)
|
require.Equal(t, 200, response.Code)
|
||||||
|
@ -2655,8 +2657,9 @@ func TestServer_MessageTemplate_JSONBody(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
body := `{"topic": "mytopic", "message": "{\"foo\":\"bar\",\"nested\":{\"title\":\"here\"}}"}`
|
body := `{"topic": "mytopic", "message": "{\"foo\":\"bar\",\"nested\":{\"title\":\"here\"}}"}`
|
||||||
response := request(t, s, "PUT", "/", body, map[string]string{
|
response := request(t, s, "PUT", "/", body, map[string]string{
|
||||||
"tpl-m": "${foo}",
|
"m": "${foo}",
|
||||||
"tpl-t": "${nested.title}",
|
"t": "${nested.title}",
|
||||||
|
"tpl": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code)
|
require.Equal(t, 200, response.Code)
|
||||||
|
@ -2669,21 +2672,23 @@ func TestServer_MessageTemplate_MalformedJSONBody(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
body := `{"topic": "mytopic", "message": "{\"foo\":\"bar\",\"nested\":{\"title\":\"here\"INVALID"}`
|
body := `{"topic": "mytopic", "message": "{\"foo\":\"bar\",\"nested\":{\"title\":\"here\"INVALID"}`
|
||||||
response := request(t, s, "PUT", "/", body, map[string]string{
|
response := request(t, s, "PUT", "/", body, map[string]string{
|
||||||
"X-Template-Message": "${foo}",
|
"X-Message": "${foo}",
|
||||||
"X-Template-Title": "${nested.title}",
|
"X-Title": "${nested.title}",
|
||||||
|
"X-Template": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code, "Got %s", response)
|
require.Equal(t, 200, response.Code, "Got %s", response)
|
||||||
m := toMessage(t, response.Body.String())
|
m := toMessage(t, response.Body.String())
|
||||||
require.Equal(t, "{\"foo\":\"bar\",\"nested\":{\"title\":\"here\"INVALID", m.Message)
|
require.Equal(t, "{\"foo\":\"bar\",\"nested\":{\"title\":\"here\"INVALID", m.Message)
|
||||||
require.Equal(t, "", m.Title)
|
require.Equal(t, "${nested.title}", m.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_MessageTemplate_PlaceholderTypo(t *testing.T) {
|
func TestServer_MessageTemplate_PlaceholderTypo(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here"}}`, map[string]string{
|
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here"}}`, map[string]string{
|
||||||
"X-Template-Message": "${food}",
|
"X-Message": "${food}",
|
||||||
"X-Template-Title": "${nested.titl}",
|
"X-Title": "${nested.titl}",
|
||||||
|
"X-Template": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code)
|
require.Equal(t, 200, response.Code)
|
||||||
|
@ -2695,7 +2700,8 @@ func TestServer_MessageTemplate_PlaceholderTypo(t *testing.T) {
|
||||||
func TestServer_MessageTemplate_MultiplePlaceholders(t *testing.T) {
|
func TestServer_MessageTemplate_MultiplePlaceholders(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here"}}`, map[string]string{
|
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here"}}`, map[string]string{
|
||||||
"X-Template-Message": "${foo} is ${nested.title}",
|
"X-Message": "${foo} is ${nested.title}",
|
||||||
|
"X-Template": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code)
|
require.Equal(t, 200, response.Code)
|
||||||
|
@ -2708,7 +2714,8 @@ func TestServer_MessageTemplate_NestedPlaceholders(t *testing.T) {
|
||||||
// i.e., ${${nested.bar}} should NOT evaluate to ${foo} and then to "bar"
|
// i.e., ${${nested.bar}} should NOT evaluate to ${foo} and then to "bar"
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here","bar":"foo"}}`, map[string]string{
|
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here","bar":"foo"}}`, map[string]string{
|
||||||
"X-Template-Message": "${${nested.bar}}",
|
"X-Message": "${${nested.bar}}",
|
||||||
|
"X-Template": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code)
|
require.Equal(t, 200, response.Code)
|
||||||
|
@ -2723,7 +2730,8 @@ func TestServer_MessageTemplate_NestedPlaceholdersFunky(t *testing.T) {
|
||||||
// included by the regex, so it is still there after replacing the placeholder, thus giving you "works!}"
|
// included by the regex, so it is still there after replacing the placeholder, thus giving you "works!}"
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here","bar":"foo"}, "${nested":{"bar":"works!"}}`, map[string]string{
|
response := request(t, s, "PUT", "/mytopic", `{"foo":"bar", "nested":{"title":"here","bar":"foo"}, "${nested":{"bar":"works!"}}`, map[string]string{
|
||||||
"X-Template-Message": "${${nested.bar}}",
|
"X-Message": "${${nested.bar}}",
|
||||||
|
"X-Template": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code)
|
require.Equal(t, 200, response.Code)
|
||||||
|
@ -2735,8 +2743,9 @@ func TestServer_MessageTemplate_FancyGJSON(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
jsonBody := `{"foo": "bar", "errors": [{"level": "severe", "url": "https://severe1.com"},{"level": "warning", "url": "https://warning.com"},{"level": "severe", "url": "https://severe2.com"}]}`
|
jsonBody := `{"foo": "bar", "errors": [{"level": "severe", "url": "https://severe1.com"},{"level": "warning", "url": "https://warning.com"},{"level": "severe", "url": "https://severe2.com"}]}`
|
||||||
response := request(t, s, "PUT", "/mytopic", jsonBody, map[string]string{
|
response := request(t, s, "PUT", "/mytopic", jsonBody, map[string]string{
|
||||||
"X-Template-Message": `${errors.#(level=="severe")#.url}`,
|
"X-Message": `${errors.#(level=="severe")#.url}`,
|
||||||
"X-Template-Title": `${errors.#(level=="severe")#|#} Severe Errors`,
|
"X-Title": `${errors.#(level=="severe")#|#} Severe Errors`,
|
||||||
|
"X-Template": "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Equal(t, 200, response.Code)
|
require.Equal(t, 200, response.Code)
|
||||||
|
|
Loading…
Reference in a new issue