test-server: extract header collecting code