1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2012-2013 Stéphane Graber
4
# Author: Stéphane Graber <stgraber@ubuntu.com>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You can find the license on Debian systems in the file
17
# /usr/share/common-licenses/GPL-2
19
from flask import url_for
20
from werkzeug.urls import uri_to_iri
23
class ReverseProxied(object):
24
def __init__(self, app, prefix):
27
self.prefix = "/%s" % prefix
31
def __call__(self, environ, start_response):
32
script_name = self.prefix
33
environ['SCRIPT_NAME'] = script_name
34
path_info = environ['PATH_INFO']
35
if path_info.startswith(script_name):
36
environ['PATH_INFO'] = path_info[len(script_name):]
38
return self.app(environ, start_response)
41
def iri_for(endpoint, **values):
43
Wrapper to url_for for utf-8 URLs.
45
return uri_to_iri(url_for(endpoint, **values))