Anonymous avatar Anonymous committed 9532234

Added a URI re-encode example middleware.

Comments (0)

Files changed (1)

     environ['SCRIPT_NAME'] = script_name
     environ['wsgi.uri_encoding'] = uri_encoding
+URI Recoding
+A middleware might re-encode the values if the `wsgi.uri_encoding` is
+`iso-8859-1` and only then.  If it performs re-encoding it must alter
+the value of `wsgi.uri_encoding` as well.  For example if an application
+accepts legacy URL as `iso-8859-7` encoded, this middleware might be
+    import codecs
+    iso_8859_1 = codecs.lookup('iso-8859-1')
+    def reencode(string):
+        return string.encode('iso-8859-1').decode('iso-8859-7')
+    def latin7_fallback_middleware(application):
+        def new_application(environ, start_response):
+            if codecs.lookup(environ['wsgi.uri_encoding']) == iso_8859_1:
+                environ['PATH_INFO'] = reencode(environ['PATH_INFO'])
+                environ['SCRIPT_NAME'] = reencode(environ['SCRIPT_NAME'])
+                environ['wsgi.uri_encoding'] = 'iso-8859-7'
+            return application(environ, start_response)
+        return new_application
 URI Encoding
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.