fix off-by-one errors when writing the response out
add mime type detection