From b1067077f56103b957fa32e5cc599c6d78ef4884 Mon Sep 17 00:00:00 2001 From: Erki Esken Date: Wed, 9 Sep 2015 16:06:36 +0300 Subject: [PATCH 1/2] Added SVG image serving support under /image and /image/svg --- httpbin/core.py | 10 +- httpbin/templates/images/svg_logo.svg | 259 ++++++++++++++++++++++++++ 2 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 httpbin/templates/images/svg_logo.svg diff --git a/httpbin/core.py b/httpbin/core.py index 178f11b..0e12a51 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -657,11 +657,13 @@ def image(): headers = get_headers() if 'accept' not in headers: return image_png() # Default media type to png - + accept = headers['accept'].lower() if 'image/webp' in accept: return image_webp() + elif 'image/svg+xml' in accept: + return image_svg() elif 'image/jpeg' in accept: return image_jpeg() elif 'image/png' in accept or 'image/*' in accept: @@ -688,6 +690,12 @@ def image_webp(): return Response(data, headers={'Content-Type': 'image/webp'}) +@app.route('/image/svg') +def image_svg(): + data = resource('images/svg_logo.svg') + return Response(data, headers={'Content-Type': 'image/svg+xml'}) + + def resource(filename): path = os.path.join( tmpl_dir, diff --git a/httpbin/templates/images/svg_logo.svg b/httpbin/templates/images/svg_logo.svg new file mode 100644 index 0000000..e4b7e58 --- /dev/null +++ b/httpbin/templates/images/svg_logo.svg @@ -0,0 +1,259 @@ + + + SVG Logo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SVG + + + + + + + + From 63c2287b4deef110813780c2401fe5d7580cdb8e Mon Sep 17 00:00:00 2001 From: Erki Esken Date: Wed, 9 Sep 2015 16:21:24 +0300 Subject: [PATCH 2/2] Added /image/svg info to docs, clarified /image route description. --- httpbin/templates/httpbin.1.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/httpbin/templates/httpbin.1.html b/httpbin/templates/httpbin.1.html index 63be780..f858286 100644 --- a/httpbin/templates/httpbin.1.html +++ b/httpbin/templates/httpbin.1.html @@ -41,10 +41,11 @@
  • /bytes/:n Generates n random bytes of binary data, accepts optional seed integer parameter.
  • /stream-bytes/:n Streams n random bytes of binary data, accepts optional seed and chunk_size integer parameters.
  • /links/:n Returns page containing n HTML links.
  • -
  • /image Returns page containing an image.
  • +
  • /image Returns page containing an image based on sent Accept header.
  • /image/png Returns page containing a PNG image.
  • /image/jpeg Returns page containing a JPEG image.
  • /image/webp Returns page containing a WEBP image.
  • +
  • /image/svg Returns page containing a SVG image.
  • /forms/post HTML form that submits to /post
  • /xml Returns some XML