Add XML declaration to contents if not present

This commit is contained in:
amercader 2013-03-01 17:25:35 +00:00
parent bd128ab58b
commit 182fbf054a
1 changed files with 4 additions and 1 deletions

View File

@ -265,6 +265,9 @@ class ViewController(BaseController):
etree.fromstring(re.sub('<\?xml(.*)\?>','',content)) etree.fromstring(re.sub('<\?xml(.*)\?>','',content))
response.content_type = 'application/xml; charset=utf-8' response.content_type = 'application/xml; charset=utf-8'
if not '<?xml' in content.split('\n')[0]:
content = u'<?xml version="1.0" encoding="UTF-8"?>\n' + content
except XMLSyntaxError: except XMLSyntaxError:
try: try:
json.loads(obj['content']) json.loads(obj['content'])
@ -274,7 +277,7 @@ class ViewController(BaseController):
pass pass
response.headers['Content-Length'] = len(content) response.headers['Content-Length'] = len(content)
return content return content.encode('utf-8')
except NotFound: except NotFound:
abort(404,_('Harvest object not found')) abort(404,_('Harvest object not found'))
except NotAuthorized,e: except NotAuthorized,e: