mirror of
https://github.com/multipleof4/ntfy.git
synced 2026-10-15 16:07:55 +00:00
Allow streaming to S3
This commit is contained in:
+8
-11
@@ -1432,16 +1432,13 @@ func (s *Server) handleBodyAsAttachment(r *http.Request, v *visitor, m *model.Me
|
||||
if m.Time > attachmentExpiry {
|
||||
return errHTTPBadRequestAttachmentsExpiryBeforeDelivery.With(m)
|
||||
}
|
||||
contentLengthStr := r.Header.Get("Content-Length")
|
||||
if contentLengthStr != "" { // Early "do-not-trust" check, hard limit see below
|
||||
contentLength, err := strconv.ParseInt(contentLengthStr, 10, 64)
|
||||
if err == nil && (contentLength > vinfo.Stats.AttachmentTotalSizeRemaining || contentLength > vinfo.Limits.AttachmentFileSizeLimit) {
|
||||
return errHTTPEntityTooLargeAttachment.With(m).Fields(log.Context{
|
||||
"message_content_length": contentLength,
|
||||
"attachment_total_size_remaining": vinfo.Stats.AttachmentTotalSizeRemaining,
|
||||
"attachment_file_size_limit": vinfo.Limits.AttachmentFileSizeLimit,
|
||||
})
|
||||
}
|
||||
// Early "do-not-trust" check, hard limit see below
|
||||
if r.ContentLength > 0 && (r.ContentLength > vinfo.Stats.AttachmentTotalSizeRemaining || r.ContentLength > vinfo.Limits.AttachmentFileSizeLimit) {
|
||||
return errHTTPEntityTooLargeAttachment.With(m).Fields(log.Context{
|
||||
"message_content_length": r.ContentLength,
|
||||
"attachment_total_size_remaining": vinfo.Stats.AttachmentTotalSizeRemaining,
|
||||
"attachment_file_size_limit": vinfo.Limits.AttachmentFileSizeLimit,
|
||||
})
|
||||
}
|
||||
if m.Attachment == nil {
|
||||
m.Attachment = &model.Attachment{}
|
||||
@@ -1461,7 +1458,7 @@ func (s *Server) handleBodyAsAttachment(r *http.Request, v *visitor, m *model.Me
|
||||
util.NewFixedLimiter(vinfo.Limits.AttachmentFileSizeLimit),
|
||||
util.NewFixedLimiter(vinfo.Stats.AttachmentTotalSizeRemaining),
|
||||
}
|
||||
m.Attachment.Size, err = s.fileCache.Write(m.ID, body, limiters...)
|
||||
m.Attachment.Size, err = s.fileCache.Write(m.ID, body, r.ContentLength, limiters...)
|
||||
if errors.Is(err, util.ErrLimitReached) {
|
||||
return errHTTPEntityTooLargeAttachment.With(m)
|
||||
} else if err != nil {
|
||||
|
||||
@@ -2218,8 +2218,8 @@ func TestServer_PublishAttachmentTooLargeContentLength(t *testing.T) {
|
||||
forEachBackend(t, func(t *testing.T, databaseURL string) {
|
||||
content := util.RandomString(5000) // > 4096
|
||||
s := newTestServer(t, newTestConfig(t, databaseURL))
|
||||
response := request(t, s, "PUT", "/mytopic", content, map[string]string{
|
||||
"Content-Length": "20000000",
|
||||
response := request(t, s, "PUT", "/mytopic", content, nil, func(r *http.Request) {
|
||||
r.ContentLength = 20000000
|
||||
})
|
||||
err := toHTTPError(t, response.Body.String())
|
||||
require.Equal(t, 413, response.Code)
|
||||
|
||||
Reference in New Issue
Block a user