If this is one of the common image formats, such as png jpg, and you see that the server is reliable, you can use the 'Content-Type' header to give what you are looking for.
But this is not as reliable as using part of the file and transferring it to python-magic, because if the server did not determine the correct format and it could set it to application / octet-stream. This is more common with video formats, but images, I think the Content-Type is fine.
Sorry, I cannot find statistics or studies on the accuracy of Content-Type. The recommended response to downloading only part of the file is also a good option.
source share