add user agent and referrer to the images request

This commit is contained in:
pluja 2024-01-27 06:52:02 +01:00
parent c64ea21904
commit a3a052b840

View File

@ -63,7 +63,16 @@ func (s *Server) handleApiPicture(c iris.Context) {
}
log.Debug().Msgf("Image %s not found in cache", service.ID)
resp, err := http.Get(service.LogoURL)
client := &http.Client{}
req, err := http.NewRequest("GET", service.LogoURL, nil)
if err != nil {
log.Error().Err(err).Msg("Failed to create HTTP request")
return
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.3")
req.Header.Set("Referer", service.Urls[0])
resp, err := client.Do(req)
if err != nil || resp.StatusCode != http.StatusOK {
log.Error().Err(err).Msg("Could not get image")
respondWithPlaceholder(c, service.Name)