Browse Source

content-type header should not appear with 204,304... http code with pyramid

Guénaël Muller 6 years ago
parent
commit
b04e8106e8
1 changed files with 10 additions and 3 deletions
  1. 10 3
      hapic/ext/pyramid/context.py

+ 10 - 3
hapic/ext/pyramid/context.py View File

61
         http_code: int,
61
         http_code: int,
62
         mimetype: str='application/json',
62
         mimetype: str='application/json',
63
     ) -> 'Response':
63
     ) -> 'Response':
64
+        # INFO - G.M - 20-04-2018 - No message_body for some http code,
65
+        # no Content-Type needed if no content
66
+        # see: https://tools.ietf.org/html/rfc2616#section-4.3
67
+        if http_code in [204, 304] or (100 <= http_code <= 199):
68
+            headers = []
69
+        else:
70
+            headers = [
71
+                ('Content-Type', mimetype),
72
+            ]
64
         from pyramid.response import Response
73
         from pyramid.response import Response
65
         return Response(
74
         return Response(
66
             body=response,
75
             body=response,
67
-            headers=[
68
-                ('Content-Type', mimetype),
69
-            ],
76
+            headers=headers,
70
             status=http_code,
77
             status=http_code,
71
         )
78
         )
72
 
79