def test_accept_extension(): """ Ignore non q= style parameters. """ environ['HTTP_ACCEPT'] = 'text/plain; cookies=chip' figure_type(environ) assert environ['tiddlyweb.type'][0] == 'text/plain'
def map_to_private(environ, start_response): """ Internally redirect a mapping uri to the mapped uri. This is done by supplying the mapped uri to the selector application for dispatch, but first redoing Query and Negotiate handling so that query parameters and content negotiation apply based on the mapped uri, not from the mapping uri. """ identifier = environ['wsgiorg.routing_args'][1]['identifier'] host, target_uri, user = _map_to_uri(environ, identifier) environ['tiddlyweb.usersign'] = _proxy_user(environ, user) try: target_uri, query_string = target_uri.split('?', 1) environ['QUERY_STRING'] = query_string.encode('utf-8') except ValueError: # no ? pass if host: environ['HTTP_HOST'] = host.encode('utf-8') environ['PATH_INFO'] = target_uri.encode('utf-8') environ['SCRIPT_NAME'] = '' # reparse the query string into tiddlyweb.query and filters Query(None).extract_query(environ) figure_type(environ) return environ['tiddlyweb.config']['selector'](environ, start_response)
def test_accept_bad_q(): """ Given a non-float q, ignore. """ environ['HTTP_ACCEPT'] = 'text/plain; q=hot, text/html, text/postscript; q=0.5' figure_type(environ) assert environ['tiddlyweb.type'][0] == 'text/html'
def test_file_extension(): """ Given a \.extension in the path_info, determine the type we want. """ environ['PATH_INFO'] = '/bags/bag0/tiddlers/bigbox.html' figure_type(environ) assert environ['tiddlyweb.type'][0] == 'text/html'
def test_accept_ill_formed_header(): """ Given an accept header in the environ, that is poorly formed, use default. """ environ['HTTP_ACCEPT'] = '; q=1.0, text/plain; q=1.0, text/html, text/x-dvi; q=0.8, text/x-c' figure_type(environ) assert environ['tiddlyweb.type'][0] == 'text/html'
def test_accept_header(): """ Given an accept header in the environ, determine the type we want. """ environ['HTTP_ACCEPT'] = 'text/plain; q=1.0, text/html; q=0.9, text/x-dvi; q=0.8, text/x-c' figure_type(environ) assert environ['tiddlyweb.type'][0] == 'text/plain'
def test_file_wins_over_header(): """ Where there is both an extension and an accept header, the extension wins. """ environ['HTTP_ACCEPT'] = 'text/plain; q=1.0, text/html, text/x-dvi; q=0.8, text/x-c' environ['PATH_INFO'] = '/bags/bag0/tiddlers/bigbox.html' figure_type(environ) assert environ['tiddlyweb.type'][0] == 'text/html'