Patchwork [01,of,15,V3] get-with-headers: add a --headeronly switch

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 16, 2013, 1:32 p.m.
Message ID <f1118507174b87df6411.1358343127@crater2.logilab.fr>
Download mbox | patch
Permalink /patch/639/
State Accepted
Commit f1118507174b87df64115ebd3bfd45ee2e21932f
Delegated to: Kevin Bullock
Headers show

Comments

Pierre-Yves David - Jan. 16, 2013, 1:32 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1358342779 -3600
# Node ID f1118507174b87df64115ebd3bfd45ee2e21932f
# Parent  66cec3c2ee00abbcaa0813eb01f34f7123eb3b49
get-with-headers: add a --headeronly switch

In some case we do not care about the actual rendering.

Patch

diff --git a/tests/get-with-headers.py b/tests/get-with-headers.py
--- a/tests/get-with-headers.py
+++ b/tests/get-with-headers.py
@@ -14,10 +14,14 @@  except ImportError:
 
 twice = False
 if '--twice' in sys.argv:
     sys.argv.remove('--twice')
     twice = True
+headeronly = False
+if '--headeronly' in sys.argv:
+    sys.argv.remove('--headeronly')
+    headeronly = True
 
 reasons = {'Not modified': 'Not Modified'} # python 2.4
 
 tag = None
 def request(host, path, show):
@@ -35,17 +39,17 @@  def request(host, path, show):
         show = sorted(h for h, v in response.getheaders()
                       if h.lower() not in show)
     for h in [h.lower() for h in show]:
         if response.getheader(h, None) is not None:
             print "%s: %s" % (h, response.getheader(h))
+    if not headeronly:
+        print
+        data = response.read()
+        sys.stdout.write(data)
 
-    print
-    data = response.read()
-    sys.stdout.write(data)
-
-    if twice and response.getheader('ETag', None):
-        tag = response.getheader('ETag')
+        if twice and response.getheader('ETag', None):
+            tag = response.getheader('ETag')
 
     return response.status
 
 status = request(sys.argv[1], sys.argv[2], sys.argv[3:])
 if twice: