I'm using Python to write a manager that will download some files given some conditions. The problem is that the conditions are to be performed against the response headers.
The example below is a simplified version of what I'm doing now. I first download the file and then test whether its name, contained in the headers, is in a list defined previously.
I'd like to know if is there a way to get the response without download the content, which takes a huge time in my real case.
# The line below download the file, but I'd like not to do it.
req = requests.get('http://some_url.com/some_file')
# Get the name of the file to test if it's the right file.
r = re.search(r'filename="(.*)";', req.headers['Content-Disposition'])
filename = None
# If the filename is present in the headers...
filename = r.groups()
# If the filename is in an authorized list...
if filename in [...]:
# Process req.content