Port ticket #6438 to 1.6-branch. Fixes a significant non-conformance to RFC 4120.