Remove Location forwarding

This commit is contained in:
Till Faelligen 2024-08-08 20:04:44 +02:00
parent a3c76e9f2f
commit 82e89743a1
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E

View file

@ -886,23 +886,7 @@ func (r *downloadRequest) fetchRemoteFile(
redirect := p.Header.Get("Location") redirect := p.Header.Get("Location")
if redirect != "" { if redirect != "" {
if !strings.HasPrefix(redirect, "https://") { return "", false, fmt.Errorf("Location header is not yet supported")
return "", false, fmt.Errorf("redirect URL must be HTTPS")
}
req, reqErr := http.NewRequest(http.MethodGet, redirect, nil)
if reqErr != nil {
return "", false, fmt.Errorf("failed to create request to %s: %w", redirect, reqErr)
}
redirectResp, reqErr := client.DoHTTPRequest(ctx, req)
if reqErr != nil {
return "", false, fmt.Errorf("error following redirect: %w", reqErr)
}
defer redirectResp.Body.Close() // nolint: errcheck
if redirectResp.StatusCode != http.StatusOK {
return "", false, fmt.Errorf("unexpected status code %d after following redirect", redirectResp.StatusCode)
}
contentLength, reader, parseErr = r.GetContentLengthAndReader(redirectResp.Header.Get("Content-Length"), redirectResp.Body, maxFileSizeBytes)
r.MediaMetadata.ContentType = types.ContentType(redirectResp.Header.Get("Content-Type"))
} else { } else {
contentLength, reader, parseErr = r.GetContentLengthAndReader(p.Header.Get("Content-Length"), p, maxFileSizeBytes) contentLength, reader, parseErr = r.GetContentLengthAndReader(p.Header.Get("Content-Length"), p, maxFileSizeBytes)
// For multipart requests, we need to get the Content-Type of the second part, which is the actual media // For multipart requests, we need to get the Content-Type of the second part, which is the actual media