adaoraul/rack-jekyll

Erroneously serving svg as application/octet-stream

colindean opened this issue · 2 comments

[colin@kid ~]$ curl -v http://localhost:4000/images/metamesh_logotext.svg
* About to connect() to localhost port 4000 (#0)
*   Trying ::1...
* connected
* Connected to localhost (::1) port 4000 (#0)
> GET /images/metamesh_logotext.svg HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:4000
> Accept: */*
>
< HTTP/1.1 200 OK
< Etag: 20ac1af-36ad-51865f43
< Content-Type: application/octet-stream
< Content-Length: 13997
< Last-Modified: Sun, 05 May 2013 13:31:47 GMT
< Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-02-22)
< Date: Sun, 05 May 2013 13:32:18 GMT
< Connection: Keep-Alive
<
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg

<!--snipped for brevity -->

I'm not doing anything funny here. It's basically a stock jekyll installation, with jekyll-sass and -haml installed as well, but not even used yet.

1.9.3p392 :001 > require 'rack'
 => true
1.9.3p392 :002 > Rack::Mime.mime_type(".svg")
 => "image/svg+xml"

I found this, and it solved my problem.

Drop this into _plugins/svg.rb:

require 'webrick'
include WEBrick
WEBrick::HTTPUtils::DefaultMimeTypes.store 'svg', 'image/svg+xml'

Jekyll should start serving SVG by default with 1.0.0 as well.