I want to "ping" a server, check the header response to see if the link is broken, and if it's not broken, actually download the response body.
Traditionally, using a sync method with the requests
module, you could send a get
request with the stream = True
parameter, and capture the headers before the response body download, deciding, in case of error (not found, for example), to abort the connection.
My problem is, doing this with the async libraries grequests
or requests-futures
has become impossible for my reduced knowdlege base.
I've tried setting the stream parameter to true in request-futures
but to no use, it still downloads the response body without letting me intervene as soon as it gets the response headers. And even if it did, I wouldn't be sure of how to proceed.
This is what I've tried:
test.py
from requests_futures.sessions import FuturesSession
session = FuturesSession()
session.stream = True
future = session.get('http://www.google.com')
response = future.result()
print(response.status_code) # Here I would assume the response body hasn't been loaded
Upon debugging I find it downloads the response body either way.
I would appreciate any solution to the initial problem, whether it follows my logic or not.