diff options
| author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 00:43:12 +0100 | 
|---|---|---|
| committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 00:43:12 +0100 | 
| commit | 1d05994fe1d9488193f01b47e92dcf11920c8f02 (patch) | |
| tree | f4040712f6914b78004895ae6192cf2162ea0804 /music.cpp | |
| parent | 1a8f351248c38445189a397035e8a2cb3182ea6a (diff) | |
Misc changes in HTTP code.
Diffstat (limited to 'music.cpp')
| -rw-r--r-- | music.cpp | 23 | 
1 files changed, 19 insertions, 4 deletions
| @@ -2,6 +2,7 @@  #include <boost/format.hpp>  #include <boost/algorithm/string/predicate.hpp> +#include <boost/filesystem/fstream.hpp>  namespace music { @@ -40,14 +41,16 @@ MusicListing *find(std::string path) {  }; // namespace music -void MusicDirectory::render(std::ostream& os) { +void MusicDirectory::render(HTTPResponse& res) { +	res.add_header("content-type", "text/html"); +  	for(MusicDirectories::iterator it = directories.begin(); it != directories.end(); it++) {  		std::string rel_path = it->path.string().substr(music::root_directory->path.string().size()); -		os << boost::format("<a href=\"%s\">%s</a><br />") % rel_path % rel_path; +		res.write(boost::str(boost::format("<a href=\"%s\">%s</a><br />") % rel_path % rel_path));  	}  	for(MusicTracks::iterator it = tracks.begin(); it != tracks.end(); it++) {  		std::string rel_path = it->path.string().substr(music::root_directory->path.string().size()); -		os << boost::format("<a href=\"%s\">%s</a><br />") % rel_path % rel_path; +		res.write(boost::str(boost::format("<a href=\"%s\">%s</a><br />") % rel_path % rel_path));  	}  } @@ -72,5 +75,17 @@ MusicDirectory::MusicDirectory(const fs::path root) {  	}  } -void MusicTrack::render(std::ostream& os) { +void MusicTrack::render(HTTPResponse& res) { +	res.add_header("content-type", "application/octet-stream"); + +	fs::ifstream is(path, std::ios::binary | std::ios::in); +	is.seekg(0, std::ios::end); +	res.add_header("content-length", boost::str(boost::format("%d") % is.tellg())); +	is.seekg(0, std::ios::beg); + +	char data[0x1000]; +	while(is.good()) { +		is.read(data, 0x1000); +		res.write(data, is.gcount()); +	}  } | 
