Splunk Dev

Setting content-type for static content

southeringtonp
Motivator

I'm trying to serve up an SVG image from within an app.

The SVG file is in appserver/static and has a .svg file extension. I'm able to retrieve the file just fine. However, the browser either fails to render the content or renders it as plain text, presumably because SplunkWeb is giving it a Content-Type of text/plain.

Does anyone know how to override the default behaviour and tell SplunkWeb (or CherryPy?) to set the correct Content-Type of image/svg+xml?

msivill_splunk
Splunk Employee
Splunk Employee

Late response, but updating answer in case anyone hits this......

If you don't mind passing your SVG via SPL and using a custom visualisation app then Scalable Vector Graphics - Custom Visualization might be another option for you (instead of updating content type for svg)

0 Karma

southeringtonp
Motivator

After beating my head against this for quite a while, the following seems to work if you have at least one custom module being loaded. In the module's python code:

import mimetypes
if not mimetypes.inited:
    mimetypes.init()
mimetypes.add_type('image/svg+xml', '.svg', True)

The upshot is that SplunkWeb is calling cherrypy.lib.static.serve_file(), which according to this page relies in turn on the python mimetypes module.

This still isn't an ideal solution, since it requires mucking about with module python code. Anyone have a more generic approach?

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...