Don't call grep on a string where a test will do

The trick here is a substring match that strips off the whole string,
making the test for a zero-length string possible.
Fix a bug with insufficient Type header handling