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 3030from .jwk .rsa import RSAKey
3131from .jwk .rsa import new_rsa_key
3232from .utils import as_unicode
33+ from .utils import check_content_type
3334from .utils import httpc_params_loader
3435
3536__author__ = "Roland Hedberg"
@@ -513,8 +514,8 @@ def _parse_remote_response(self, response):
513514 """
514515 # Check if the content type is the right one.
515516 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" ])
518519 except KeyError :
519520 pass
520521
Original file line number Diff line number Diff line change 11import base64
2+ import cgi
23import functools
34import importlib
45import json
@@ -264,3 +265,9 @@ def httpc_params_loader(httpc_params):
264265 if "timeout" not in httpc_params :
265266 httpc_params ["timeout" ] = DEFAULT_HTTPC_TIMEOUT
266267 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