Fix :callback and add content-type

master
pictuga 2014-06-28 01:20:47 +02:00
parent 0ec7c2f3e6
commit 6cc3e7eb93
1 changed files with 7 additions and 2 deletions

View File

@ -693,8 +693,11 @@ def After(rss, options):
if item.content:
item.content = conv.handle(item.content)
if options.callback and re.match(r'^[a-zA-Z0-9\.]+$', options.callback) is not None:
return '%s(%s)' % (options.callback, rss.tojson())
if options.callback:
if re.match(r'^[a-zA-Z0-9\.]+$', options.callback) is not None:
return '%s(%s)' % (options.callback, rss.tojson())
else:
raise MorssException('Invalid callback var name')
elif options.json:
if options.indent:
return rss.tojson(indent=4)
@ -768,6 +771,8 @@ def cgi_app(environ, start_response):
headers['content-type'] = 'text/plain'
elif options.json:
headers['content-type'] = 'application/json'
elif options.callback:
headers['content-type'] = 'application/javascript'
elif options.csv:
headers['content-type'] = 'text/csv'
headers['content-disposition'] = 'attachment; filename="feed.csv"'