Correctly handle whitespaces and trailing whitespaces while parse headers