From 36de166b2871ec52f3e2483fbb61e1e4ba8ff8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88kull=20So=CC=81lberg=20Au=C3=B0unsson?= Date: Sat, 14 Jul 2012 14:27:11 +0000 Subject: [PATCH] Simplify vendor extension content-types since they are most likely lexable --- httpie/pretty.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/httpie/pretty.py b/httpie/pretty.py index 8c6bdbee..9ecb5d10 100644 --- a/httpie/pretty.py +++ b/httpie/pretty.py @@ -1,4 +1,5 @@ import os +import re import json import pygments @@ -18,6 +19,8 @@ FORMATTER = (Terminal256Formatter if '256color' in os.environ.get('TERM', '') else TerminalFormatter) +application_content_type_re = re.compile(r'application/(.+\+)?(json|xml)$') + class PrettyHttp(object): @@ -33,12 +36,18 @@ class PrettyHttp(object): def body(self, content, content_type): content_type = content_type.split(';')[0] + application_match = re.match(application_content_type_re, content_type) + if application_match: + # Strip vendor and extensions from Content-Type + vendor, extension = application_match.groups() + content_type = content_type.replace(vendor, u"") + try: lexer = get_lexer_for_mimetype(content_type) except ClassNotFound: return content - if content_type == 'application/json': + if content_type == "application/json": try: # Indent and sort the JSON data. content = json.dumps(json.loads(content),