Fix h1 detection and improve tests