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:

- 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.


Change-Id: Ia68fa8acb7a27c17f9da7eea587112da4dedb892
Closes-Bug: #1976220
(cherry picked from commit e8dfc6b037)
Hiromu Asahina 1 year ago
parent 96ae85ee4d
commit 51ef6ca2cb

@ -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")