lib/rack/musicindex.rb in rack-musicindex-0.1.1 vs lib/rack/musicindex.rb in rack-musicindex-0.2.0

- old
+ new

@@ -19,11 +19,11 @@ update_files if dirs[path_info] serve_podcast(env) - elsif static_paths.include?(path_info) + elsif static_paths.include?(URI.unescape(path_info)) serve_mp3(env) else status, headers, response = @app.call(env) end end @@ -31,26 +31,30 @@ private def serve_podcast(env) status, headers, response = @app.call(env) + method = env['REQUEST_METHOD'] body = podcast(env) + headers['Content-Type'] = 'application/xml;charset=utf-8' headers["Content-Length"] = body.bytesize.to_s - [200, headers, [body]] + [200, headers, method == 'GET' ? [body] : []] end def serve_mp3(env) status, headers, response = @app.call(env) - path_info = env['PATH_INFO'] + method = env['REQUEST_METHOD'] + path_info = URI.unescape(env['PATH_INFO']) body = open(static_paths[path_info], 'rb').read + headers["Content-Type"] = 'audio/mpeg' headers["Content-Length"] = body.bytesize.to_s - [200, headers, [body]] + [200, headers, method == 'GET' ? [body] : []] end def dirs @dirs end @@ -101,11 +105,11 @@ def podcast(env) path = env['PATH_INFO'] req = Rack::Request.new(env) url = req.url files = files(path) - xml = ::Builder::XmlMarkup.new + xml = ::Builder::XmlMarkup.new(:indent => 2) xml.instruct! :xml, :version => '1.0' xml.rss :version => "2.0", 'xmlns:itunes' => 'http://www.itunes.com/dtds/podcast-1.0.dtd' do xml.channel do xml.title path @@ -114,11 +118,11 @@ files.each do |file| tag = id3(file) author = tag[:artist] name = ::File.basename(file) - item_link = url + '/' + name + item_link = URI.escape(url + '/' + name) xml.item do xml.title tag[:name] || name xml.description name xml.link item_link @@ -126,10 +130,9 @@ xml.enclosure :url => item_link if author xml.author author xml.itunes :author, author - xml.itunes :summary, author end end end end end