From 983651b924d8fb28fcfbc3fe75cd8608ed54fa29 Mon Sep 17 00:00:00 2001 From: Miguel Dias Costa Date: Tue, 12 Feb 2019 17:24:19 +0800 Subject: [PATCH] make REST client actually return headers when http method is HEAD --- easybuild/base/rest.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/easybuild/base/rest.py b/easybuild/base/rest.py index f3fe468f5c..42c9650b32 100644 --- a/easybuild/base/rest.py +++ b/easybuild/base/rest.py @@ -170,11 +170,14 @@ def request(self, method, url, body, headers, content_type=None): # TODO: in recent python: Context manager conn = self.get_connection(method, url, body, headers) status = conn.code - body = conn.read() - try: - pybody = json.loads(body) - except ValueError: - pybody = body + if method == self.HEAD: + pybody = conn.headers + else: + body = conn.read() + try: + pybody = json.loads(body) + except ValueError: + pybody = body fancylogger.getLogger().debug('reponse len: %s ', len(pybody)) conn.close() return status, pybody