Skip to content

Instantly share code, notes, and snippets.

@fser
Created May 24, 2018 17:44
Show Gist options
  • Save fser/6410b9899dc0f4c8c74b37f5e7231f36 to your computer and use it in GitHub Desktop.
Save fser/6410b9899dc0f4c8c74b37f5e7231f36 to your computer and use it in GitHub Desktop.
Chronomètre le temps de réponse pour une requête HTTP et affiche le header `X-Backend-Server`
#!/usr/bin/env python
import requests
import sys
from timeit import default_timer as timer
def get_page(url):
r = requests.get(url)
return r.headers.get('X-Backend-Server', 'No backend returned')
if __name__ == '__main__':
if len(sys.argv) != 2:
print "%s: URL" % (sys.argv[0])
sys.exit (1)
start = timer()
backend = get_page(sys.argv[1])
end = timer()
print "{} responded in {}s".format(backend, (end - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment