1. Erik van Zijst
  2. urlblast

Commits

Erik van Zijst  committed e2fe74a

Made Keep-Alive support configurable.

  • Participants
  • Parent commits 966c1e2
  • Branches master

Comments (0)

Files changed (1)

File urlblast.py

View file
  • Ignore whitespace
 class TimeoutException(Exception):
     pass
 
-options, remainder = getopt.getopt(sys.argv[1:], 't:', ['time='])
+options, remainder = getopt.getopt(sys.argv[1:], 't:k:',
+                                   ['time=', 'keepalive='])
 duration = 1
+keepalive = True
 
 def die(message=None):
     if message:
 Usage: %s OPTIONS url
 
 OPTIONS
-    -t, --time      length of the test (seconds, float)
+    -t, --time          length of the test (seconds, float)
+    -k, --keepalive     toggle keepalive [yes|no] (default is yes)
 """ % sys.argv[0]
     exit(1)
 
                 raise ValueError
         except ValueError:
             die('Error: invalid duration: %s' % arg)
+    elif opt in ('-k', '--keepalive'):
+        if arg.lower() in ('no', 'n', '0', 'off'):
+            keepalive = False
     else:
         die()
 if len(remainder) is not 1:
 count = 0
 try:
     with sessions.session() as conn:
+        conn.config['keep_alive'] = keepalive
         with timeout(duration, TimeoutException):
             while True:
                 result = conn.get(url, verify=False)