Using the Python requests library, is there a way to fetch the HTTP response headers and only fetch the body over the network when the Content-Type header is some specific type?
I can of course issue a HEAD request, inspect the Content-Type and if the type matches, issue a GET request. But is there a way to avoid fetching the HTTP headers twice?
I choose to do requests.head(), inspect the content-type and if the type is something that should be fetched, do requests.get() to get the body.
The extra network I/O of fetching headers twice is outweighed by not fetching bodies of other content types.
Fetch content of HTML page using python requests dependig on Content-Type?