From 2c51804e0be3e6e886fa001a054a9ed23fcb5a47 Mon Sep 17 00:00:00 2001 From: phouse512 Date: Thu, 10 Sep 2015 19:25:33 -0500 Subject: [PATCH] Added 406 unsupported media type response to /image --- httpbin/core.py | 2 +- httpbin/helpers.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/httpbin/core.py b/httpbin/core.py index 0e12a51..d422c59 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -669,7 +669,7 @@ def image(): elif 'image/png' in accept or 'image/*' in accept: return image_png() else: - return status_code(404) + return status_code(406) # Unsupported media type @app.route('/image/png') diff --git a/httpbin/helpers.py b/httpbin/helpers.py index 914ddb7..404077c 100644 --- a/httpbin/helpers.py +++ b/httpbin/helpers.py @@ -54,6 +54,14 @@ ROBOT_TXT = """User-agent: * Disallow: /deny """ +ACCEPTED_MEDIA_TYPES = [ + 'image/webp', + 'image/svg+xml', + 'image/jpeg', + 'image/png', + 'image/*' +] + ANGRY_ASCII =""" .-''''''-. .' _ _ '. @@ -209,6 +217,13 @@ def status_code(code): 'x-more-info': 'http://vimeo.com/22053820' } ), + 406: dict(data=json.dumps({ + 'message': 'Client did not request a supported media type.', + 'accept': ACCEPTED_MEDIA_TYPES + }), + headers={ + 'Content-Type': 'application/json' + }), 407: dict(headers={'Proxy-Authenticate': 'Basic realm="Fake Realm"'}), 418: dict( # I'm a teapot! data=ASCII_ART,