From 0897170cf782f1185693bda8874351ffee8ceef5 Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Tue, 8 Jul 2008 08:35:35 -0400 Subject: [PATCH 1/1] meilleure gestion des content-type --- rest.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rest.py b/rest.py index cabebfc..7e0edc0 100644 --- a/rest.py +++ b/rest.py @@ -18,9 +18,14 @@ from objet import ObjetInconnu # TODO : ajouter un middleware de cache (beaker, basé sur REQUEST_URI quand la methode est GET) # from beaker.middleware import CacheMiddleware -# formats de sortie autorisés, et content-type correspondant -formats = { 'xml': 'application/xml', 'html': 'text/html', 'txt': 'text/plain', 'json': 'application/json', 'rss': 'application/rss+xml', 'debug': 'text/plain' } - +# content-type correspondant a certains formats +contenttype = { 'xml': 'application/xml', + 'rss': 'application/rss+xml', + 'html': 'text/html', + 'txt': 'text/plain', + 'json': 'application/json', + 'csv': 'text/csv', + 'debug': 'text/plain' } # les routes RESTful (cf http://routes.groovie.org/manual.html#restful-services) mapper = Mapper() @@ -60,7 +65,7 @@ def dispatcher(environ, start_response): try: # On lance la méthode et on renvoie le résultat type, output = method(target_class(environ)) - start_response("200 OK", [('Content-type', formats[type] + "; charset=utf-8")]) + start_response("200 OK", [('Content-type', contenttype.get(type,'text/plain') + "; charset=utf-8")]) return output.encode('utf-8') # gestion des problèmes possibles pendant l'exécution except ObjetInconnu, type: -- 1.7.10.4