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,12 +61,19 @@ class PyramidContext(BaseContext):
61 61
         http_code: int,
62 62
         mimetype: str='application/json',
63 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 73
         from pyramid.response import Response
65 74
         return Response(
66 75
             body=response,
67
-            headers=[
68
-                ('Content-Type', mimetype),
69
-            ],
76
+            headers=headers,
70 77
             status=http_code,
71 78
         )
72 79