public void EncodeHeaders_WithCustomUnicodeHeaders_ShouldEncodeHeaders()
        {
            _headers.Add("X-Custom", CustomUnicodeHeaderValue);
            _message.EncodeHeaders(_headers, false);

            string encodedHeader = _headers.Get("X-Custom");

            Assert.True(encodedHeader.StartsWith("="));
            Assert.True(encodedHeader.EndsWith("="));
            //should contain no unicode
            Assert.False(ContainsNonAscii(encodedHeader), encodedHeader);

            Assert.Equal(Encoding.UTF8, _message.HeadersEncoding);

            // Allow Unicode
            _headers.Clear();
            _headers.Add("X-Custom", CustomUnicodeHeaderValue);
            _message.EncodeHeaders(_headers, true);

            encodedHeader = _headers.Get("X-Custom");
            Assert.False(encodedHeader.StartsWith("="));
            Assert.False(encodedHeader.EndsWith("="));
            //should contain unicode
            Assert.True(ContainsNonAscii(encodedHeader), encodedHeader);
        }
예제 #2
0
 internal Response(RequestContext requestContext)
 {
     // TODO: Verbose log
     RequestContext = requestContext;
     Headers        = new HeaderCollection();
     // We haven't started yet, or we're just buffered, we can clear any data, headers, and state so
     // that we can start over (e.g. to write an error message).
     _nativeResponse    = new HttpApiTypes.HTTP_RESPONSE_V2();
     Headers.IsReadOnly = false;
     Headers.Clear();
     _reasonPhrase = null;
     _boundaryType = BoundaryType.None;
     _nativeResponse.Response_V1.StatusCode           = (ushort)StatusCodes.Status200OK;
     _nativeResponse.Response_V1.Version.MajorVersion = 1;
     _nativeResponse.Response_V1.Version.MinorVersion = 1;
     _responseState      = ResponseState.Created;
     _expectedBodyLength = 0;
     _nativeStream       = null;
     _cacheTtl           = null;
     _authChallenges     = RequestContext.Server.Options.Authentication.Schemes;
 }