Skip to content

Commit

Permalink
Replace MIMEAccept with acceptparse.create_accept_header
Browse files Browse the repository at this point in the history
This is the new API that WebOb makes available and follows the
standards.
  • Loading branch information
digitalresistor committed May 19, 2018
1 parent 62dbd45 commit 12a58d2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pyramid/httpexceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
from zope.interface import implementer

from webob import html_escape as _html_escape
from webob.acceptparse import MIMEAccept
from webob.acceptparse import create_accept_header

from pyramid.compat import (
class_types,
Expand Down Expand Up @@ -250,10 +250,12 @@ def prepare(self, environ):
html_comment = ''
comment = self.comment or ''
accept_value = environ.get('HTTP_ACCEPT', '')
accept = MIMEAccept(accept_value)
accept = create_accept_header(accept_value)
# Attempt to match text/html or application/json, if those don't
# match, we will fall through to defaulting to text/plain
match = accept.best_match(['text/html', 'application/json'])
acceptable = accept.acceptable_offers(['text/html', 'application/json'])
acceptable = [offer[0] for offer in acceptable] + ['text/plain']
match = acceptable[0]

if match == 'text/html':
self.content_type = 'text/html'
Expand Down

0 comments on commit 12a58d2

Please sign in to comment.