Fix usage of deprecated .best_match()
The webob emits a warning for best_match method for the reason that its algorithm does not conform to RFC 7231 [1]. This patch replace `best_match` with `acceptable_offers` as v2 API does [2]. The following deprecation warnings are gone with the patch: - cceptparse.py:1047: DeprecationWarning: The behavior of AcceptValidHeader.best_match is currently being maintained for backward compatibility, but it will be deprecated in the future, as it does not conform to the RFC. [1] https://docs.pylonsproject.org/projects/webob/en/stable/api/webob.html#webob.acceptparse.AcceptValidHeader.best_match [2] https://github.com/openstack/tacker/blob/master/tacker/sol_refactored/api/wsgi.py#L37 Change-Id: Ia68fa8acb7a27c17f9da7eea587112da4dedb892 Closes-Bug: #1976220
This commit is contained in:
parent
c47646f783
commit
e8dfc6b037
|
@ -357,11 +357,11 @@ class Request(webob.Request):
|
|||
type_from_header = self.get_content_type()
|
||||
if type_from_header:
|
||||
return type_from_header
|
||||
ctypes = ['application/json', 'text/plain', 'application/zip']
|
||||
offers = ['application/json', 'text/plain', 'application/zip']
|
||||
|
||||
# Finally search in Accept-* headers
|
||||
bm = self.accept.best_match(ctypes)
|
||||
return bm or 'application/json'
|
||||
ctypes = self.accept.acceptable_offers(offers)
|
||||
return ctypes[0][0] if ctypes else 'application/json'
|
||||
|
||||
def get_content_type(self):
|
||||
allowed_types = ("application/json", "application/zip")
|
||||
|
|
Loading…
Reference in New Issue