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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...