Return HTTP status codes for error conditions for various commands

This returns 404 Not found for most errors, the only exception is for the stats, where it will return 400
Bad request for unknown statistics types. Note that this patch also fixes various incomplete header errors,
which manifest themselves like this in the web server error log: "Premature end of script headers:
cgit.cgi".