Terahertz gas spectroscopy through self-mixing in a quantum-cascade laser