示例#1
0
        public unsafe void ReadHeaderName_InvalidHeaderLine_ThrowsHttpRequestException(string headerLine)
        {
            byte[] buffer = headerLine.Select(c => checked ((byte)c)).ToArray();

            fixed(byte *pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked ((ulong)buffer.Length));

                string headerName;
                string headerValue;

                Assert.Throws <HttpRequestException>(() => reader.ReadHeader(out headerName, out headerValue));
            }
        }
示例#2
0
        public unsafe void ReadHeader_ValidHeaderLine_HeaderReturned(string headerLine, string expectedHeaderName, string expectedHeaderValue)
        {
            byte[] buffer = headerLine.Select(c => checked ((byte)c)).ToArray();
            fixed(byte *pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked ((ulong)buffer.Length));

                string headerName;
                string headerValue;

                Assert.True(reader.ReadHeader(out headerName, out headerValue));
                Assert.Equal(expectedHeaderName, headerName);
                Assert.Equal(expectedHeaderValue, headerValue);
            }
        }
示例#3
0
        public unsafe void ReadHeader_EmptyBuffer_ReturnsFalse()
        {
            byte[] buffer = new byte[2]; // Non-empty array so we can get a valid pointer using fixed.
            ulong  length = 0;           // But a length of 0 for empty.

            fixed(byte *pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), length);

                string headerName;
                string headerValue;

                Assert.False(reader.ReadHeader(out headerName, out headerValue));
                Assert.Null(headerName);
                Assert.Null(headerValue);
            }
        }
        public unsafe void ReadHeaderName_InvalidHeaderLine_ThrowsHttpRequestException(string headerLine)
        {
            byte[] buffer = headerLine.Select(c => checked((byte)c)).ToArray();

            fixed (byte* pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked((ulong)buffer.Length));

                string headerName;
                string headerValue;
                Assert.Throws<HttpRequestException>(() => reader.ReadHeader(out headerName, out headerValue));
            }
        }
        public unsafe void ReadHeader_EmptyBuffer_ReturnsFalse()
        {
            byte[] buffer = new byte[2]; // Non-empty array so we can get a valid pointer using fixed.
            ulong length = 0; // But a length of 0 for empty.

            fixed (byte* pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), length);

                string headerName;
                string headerValue;
                Assert.False(reader.ReadHeader(out headerName, out headerValue));
                Assert.Null(headerName);
                Assert.Null(headerValue);
            }
        }
        public unsafe void ReadHeader_ValidHeaderLine_HeaderReturned(string expectedHeaderName, string expectedHeaderValue, bool spaceAfterColon)
        {
            string headerLine = $"{expectedHeaderName}:{(spaceAfterColon ? " " : "")}{expectedHeaderValue}";

            byte[] buffer = headerLine.Select(c => checked((byte)c)).ToArray();

            fixed (byte* pBuffer = buffer)
            {
                var reader = new CurlResponseHeaderReader(new IntPtr(pBuffer), checked((ulong)buffer.Length));

                string headerName;
                string headerValue;
                Assert.True(reader.ReadHeader(out headerName, out headerValue));
                Assert.Equal(expectedHeaderName, headerName);
                Assert.Equal(expectedHeaderValue, headerValue);
            }
        }