Handle malformed headers more gracefully.

Closes #699.