Pylons/webob — pull request #56 by lmctv (2012-06-07 15:27:07+00:00)
Title: Fix case-sensitive behaviour in MIMEAccept and AcceptCharset.

I'm enclosing an adapted version of the test script posted by Graham Klyne at
https://groups.google.com/forum/?fromgroups#!topic/pylons-discuss/XkDlQTj9m44

The behavior Klyne observed contradicts the case-insensitivity required in rfc 2616.

if the following webob_accept_tests.py is being run with unpatched webob,
a mixed-case accept header will not match a lower-case offer:

$ wget --header='Accept: text/HtmL' 127.0.0.1:6543/
--2012-06-07 14:53:52-- http://127.0.0.1:6543/
Connecting to 127.0.0.1:6543... connected.
HTTP request sent, awaiting response... 404 Not Found
2012-06-07 14:53:52 ERROR 404: Not Found.

After installing a patched WebOb, the very same request will be
fulfilled:

$ wget --header='Accept: text/HtmL' 127.0.0.1:6543/
--2012-06-07 15:00:57-- http://127.0.0.1:6543/
Connecting to 127.0.0.1:6543... connected.
HTTP request sent, awaiting response... 200 OK
Length: 92 [text/html]
Saving to: `index.html'

100%[==================================>] 92 --.-K/s in 0s

2012-06-07 15:00:57 (6.99 MB/s) - `index.html' saved [92/92]

webob_accept_tests.py:
```python
#!python
# encoding: utf-8

from pyramid.config import Configurator
from wsgiref.simple_server import make_server
from pyramid.view import view_config
from pyramid.response import Response

import sys

@view_config(route_name='service', request_method='GET',
accept='application/xml')
def service_xml(request):
return Response('\n',
content_type='application/xml')

@view_config(route_name='service', request_method='GET',
accept='text/turtle')
def service_turtle(request):
return Response('Turtle, route_name=service\n', content_type='text/turtle')

@view_config(route_name='service', request_method='GET',
accept="text/HTML")
def service_html(request):
return Response('

html service

route_name=service

\n')

@view_config(route_name='service', request_method='GET',
accept='text/plain')
def service_plaintext(request):
return Response('Plain text, route_name=service\n', content_type='text/plain')

if __name__ == '__main__':
# configuration settings
if len(sys.argv) > 1:
httpport = int(sys.argv[1])
else:
httpport = 6543
settings = {}
settings['reload_all'] = True
settings['debug_all'] = True
# configuration setup
config = Configurator(settings=settings)
config.add_route(name='service', pattern='/')
config.scan()
# serve app
app = config.make_wsgi_app()
server = make_server('', httpport, app)
print 'Listening on port %i' % httpport
server.serve_forever()
```