Set correct Content-Type

This commit is contained in:
Till Faelligen 2024-07-02 08:52:28 +02:00
parent 53e545ddc5
commit e8b69fba03
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E

View file

@ -840,6 +840,10 @@ func (r *downloadRequest) fetchRemoteFile(
} }
defer resp.Body.Close() // nolint: errcheck defer resp.Body.Close() // nolint: errcheck
// If this wasn't a multipart response, set the Content-Type now. Will be overwritten
// by the multipart Content-Type below.
r.MediaMetadata.ContentType = types.ContentType(resp.Header.Get("Content-Type"))
var contentLength int64 var contentLength int64
var reader io.Reader var reader io.Reader
var parseErr error var parseErr error
@ -869,6 +873,8 @@ func (r *downloadRequest) fetchRemoteFile(
if !first { if !first {
readCloser := io.NopCloser(p) readCloser := io.NopCloser(p)
contentLength, reader, parseErr = r.GetContentLengthAndReader(p.Header.Get("Content-Length"), readCloser, maxFileSizeBytes) contentLength, reader, parseErr = r.GetContentLengthAndReader(p.Header.Get("Content-Length"), readCloser, maxFileSizeBytes)
// For multipart requests, we need to get the Content-Type of the second part, which is the actual media
r.MediaMetadata.ContentType = types.ContentType(p.Header.Get("Content-Type"))
break break
} }
@ -890,7 +896,6 @@ func (r *downloadRequest) fetchRemoteFile(
} }
r.MediaMetadata.FileSizeBytes = types.FileSizeBytes(contentLength) r.MediaMetadata.FileSizeBytes = types.FileSizeBytes(contentLength)
r.MediaMetadata.ContentType = types.ContentType(resp.Header.Get("Content-Type"))
dispositionHeader := resp.Header.Get("Content-Disposition") dispositionHeader := resp.Header.Get("Content-Disposition")
if _, params, e := mime.ParseMediaType(dispositionHeader); e == nil { if _, params, e := mime.ParseMediaType(dispositionHeader); e == nil {