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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...