Trim header correctly

This was previously done on the wrong end, due to a non-compliant client used for testing.