File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 30
30
from .jwk .rsa import RSAKey
31
31
from .jwk .rsa import new_rsa_key
32
32
from .utils import as_unicode
33
+ from .utils import check_content_type
33
34
from .utils import httpc_params_loader
34
35
35
36
__author__ = "Roland Hedberg"
@@ -513,8 +514,8 @@ def _parse_remote_response(self, response):
513
514
"""
514
515
# Check if the content type is the right one.
515
516
try :
516
- if response .headers ["Content-Type" ] != "application/json" :
517
- LOGGER .warning ("Wrong Content_type (%s)" , response .headers ["Content-Type" ])
517
+ if not check_content_type ( response .headers ["Content-Type" ], "application/json" ) :
518
+ LOGGER .warning ("Wrong Content_type (%s)" , respeonse .headers ["Content-Type" ])
518
519
except KeyError :
519
520
pass
520
521
Original file line number Diff line number Diff line change 1
1
import base64
2
+ import cgi
2
3
import functools
3
4
import importlib
4
5
import json
@@ -264,3 +265,9 @@ def httpc_params_loader(httpc_params):
264
265
if "timeout" not in httpc_params :
265
266
httpc_params ["timeout" ] = DEFAULT_HTTPC_TIMEOUT
266
267
return httpc_params
268
+
269
+
270
+ def check_content_type (content_type , mime_type ):
271
+ """Return True if the content type contains the MIME type"""
272
+ mt , _ = cgi .parse_header (content_type )
273
+ return mime_type == mt
Original file line number Diff line number Diff line change
1
+ from cryptojwt .utils import check_content_type
2
+
3
+
4
+ def test_check_content_type ():
5
+ assert check_content_type (content_type = "application/json" , mime_type = "application/json" ) == True
6
+ assert (
7
+ check_content_type (
8
+ content_type = "application/json; charset=utf-8" , mime_type = "application/json"
9
+ )
10
+ == True
11
+ )
12
+ assert (
13
+ check_content_type (
14
+ content_type = "application/html; charset=utf-8" , mime_type = "application/json"
15
+ )
16
+ == False
17
+ )
You can’t perform that action at this time.
0 commit comments