From 14ca843c5bb32b7a0e789237c7f42f50dbc8dd6f Mon Sep 17 00:00:00 2001 From: Arvind Date: Tue, 26 Aug 2014 13:02:45 +0530 Subject: [PATCH] Adding API for getting media type of a resource at an URL. --- swtr/server.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/swtr/server.py b/swtr/server.py index 39f3d00..66e947f 100644 --- a/swtr/server.py +++ b/swtr/server.py @@ -220,6 +220,15 @@ def addCSS(src, el): style.set("type", "text/css") +@app.route('/getMediaType') +def getMediaType(): + request = requests.get(flask.request.args['where']) + content = request.text + if imghdr.what('ignore', content) is None: + return flask.jsonify({'type': 'html'}) + else: + return flask.jsonify({'type': 'image'}) + # if the app is run directly from command-line # assume its being run locally in a dev environment if __name__ == '__main__': -- 1.7.10.4