Patchwork [20,of,22,V2-Series-D] get-with-headers: add a --headeronly switch

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 14, 2013, 8:35 p.m.
Message ID <cd73d1a61f4243c73b70.1358195752@yamac.lan>
Download mbox | patch
Permalink /patch/616/
State Superseded
Commit f1118507174b87df64115ebd3bfd45ee2e21932f
Headers show

Comments

Pierre-Yves David - Jan. 14, 2013, 8:35 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1358195035 -3600
# Node ID cd73d1a61f4243c73b702ca266ef0fc8a0dca467
# Parent  e7888fbf2a7d88d9674d392f36575b67ca9ef5ea
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
+headonly = False
+if '--headeronly' in sys.argv:
+    sys.argv.remove('--headeronly')
+    headonly = True
 
 reasons = {'Not modified': 'Not Modified'} # python 2.4
 
 tag = None
 def request(host, path, show):
@@ -32,17 +36,17 @@  def request(host, path, show):
     response = conn.getresponse()
     print response.status, reasons.get(response.reason, response.reason)
     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 headonly:
+        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: