A class that encodes and decodes the body of an HTTP request or an HTTP response for a specified HTTP content encoding method.
コード例 #1
0
        public void Decode_WithNull_ReturnsNull()
        {
            var encoding  = new ContentEncoder("gzip");
            var nullBytes = encoding.Decode(null);

            Assert.IsNull(nullBytes);
        }
コード例 #2
0
        public void Decode_WithNull_ReturnsNull()
        {
            var encoding = new ContentEncoder("gzip");
            var nullBytes = encoding.Decode(null);

            Assert.IsNull(nullBytes);
        }
コード例 #3
0
        public void Constructor_WithValue_MethodUpdated()
        {
            const string Expected = "gzip";

            var encoding = new ContentEncoder(Expected);
            Assert.AreEqual(Expected, encoding.Method);
        }
コード例 #4
0
        public void Decode_UsingGzip_ReturnsDecompressed()
        {
            var encoding = new ContentEncoder("gzip");
            var actual   = encoding.Decode(_helloWorldGZip);

            CollectionAssert.AreEqual(_helloWorldUtf8, actual);
        }
コード例 #5
0
        public void Decode_UsingUnknownMethod_ReturnsSame()
        {
            var encoding = new ContentEncoder("badmethod");
            var actual   = encoding.Decode(_helloWorldGZip);

            CollectionAssert.AreEqual(_helloWorldGZip, actual);
        }
コード例 #6
0
        public void Decode_UsingDeflate_ReturnsDecompressed()
        {
            var encoding = new ContentEncoder("deflate");
            var actual   = encoding.Decode(_helloWorldDeflate);

            CollectionAssert.AreEqual(_helloWorldUtf8, actual);
        }
コード例 #7
0
        public void Constructor_WithValue_MethodUpdated()
        {
            const string Expected = "gzip";

            var encoding = new ContentEncoder(Expected);

            Assert.AreEqual(Expected, encoding.Method);
        }
コード例 #8
0
        public void Encode_UsingDeflate_ReturnsCompressed()
        {
            var encoding = new ContentEncoder("deflate");
            var actual   = encoding.Encode(_helloWorldUtf8);

            // assert that we got back something different
            CollectionAssert.AreNotEqual(_helloWorldUtf8, actual);

            var roundTrip = encoding.Decode(actual);

            CollectionAssert.AreEqual(_helloWorldUtf8, roundTrip);
        }
コード例 #9
0
        public void Encode_UsingGzip_ReturnsCompressed()
        {
            var encoding = new ContentEncoder("gzip");
            var actual   = encoding.Encode(_helloWorldUtf8);

            CollectionAssert.AreNotEqual(_helloWorldUtf8, actual);

            // assert that the gzip header is present
            Assert.AreEqual(actual[0], 31);
            Assert.AreEqual(actual[1], 139);

            var roundTrip = encoding.Decode(actual);

            CollectionAssert.AreEqual(_helloWorldUtf8, roundTrip);
        }
コード例 #10
0
 public void Decode_UsingUnknownMethod_ReturnsSame()
 {
     var encoding = new ContentEncoder("badmethod");
     var actual = encoding.Decode(_helloWorldGZip);
     CollectionAssert.AreEqual(_helloWorldGZip, actual);
 }
コード例 #11
0
 public void Decode_UsingGzip_ReturnsDecompressed()
 {
     var encoding = new ContentEncoder("gzip");
     var actual = encoding.Decode(_helloWorldGZip);
     CollectionAssert.AreEqual(_helloWorldUtf8, actual);
 }
コード例 #12
0
 public void Decode_UsingDeflate_ReturnsDecompressed()
 {
     var encoding = new ContentEncoder("deflate");
     var actual = encoding.Decode(_helloWorldDeflate);
     CollectionAssert.AreEqual(_helloWorldUtf8, actual);
 }
コード例 #13
0
 public void Constructor_WithNullMethod_MethodIsStringEmpty()
 {
     var encoding = new ContentEncoder(null);
     Assert.AreEqual(string.Empty, encoding.Method);
 }
コード例 #14
0
        public void Constructor_WithNullMethod_MethodIsStringEmpty()
        {
            var encoding = new ContentEncoder(null);

            Assert.AreEqual(string.Empty, encoding.Method);
        }
コード例 #15
0
        public void Encode_UsingDeflate_ReturnsCompressed()
        {
            var encoding = new ContentEncoder("deflate");
            var actual = encoding.Encode(_helloWorldUtf8);

            // assert that we got back something different
            CollectionAssert.AreNotEqual(_helloWorldUtf8, actual);

            var roundTrip = encoding.Decode(actual);

            CollectionAssert.AreEqual(_helloWorldUtf8, roundTrip);
        }
コード例 #16
0
        public void Encode_UsingGzipUppercase_ReturnsCompressed()
        {
            var encoding = new ContentEncoder("GZIP");
            var actual = encoding.Encode(_helloWorldUtf8);

            // assert that we got back something different
            CollectionAssert.AreNotEqual(_helloWorldUtf8, actual);

            // assert that the gzip header is present
            Assert.AreEqual(actual[0], 31);
            Assert.AreEqual(actual[1], 139);

            var roundTrip = encoding.Decode(actual);
            CollectionAssert.AreEqual(_helloWorldUtf8, roundTrip);
        }
コード例 #17
0
ファイル: StumpsHandler.cs プロジェクト: Cayan-LLC/stumps
        /// <summary>
        ///     Populates the response of the HTTP context from the Stump.
        /// </summary>
        /// <param name="incommingHttpContext">The incomming HTTP context.</param>
        /// <param name="stump">The <see cref="T:Stumps.Stump"/> used to populate the response.</param>
        private void PopulateResponse(IStumpsHttpContext incommingHttpContext, Stump stump)
        {

            // Write the status code information
            incommingHttpContext.Response.StatusCode = stump.Response.StatusCode;
            incommingHttpContext.Response.StatusDescription = stump.Response.StatusDescription;

            // Write the headers
            incommingHttpContext.Response.Headers.Clear();

            stump.Response.Headers.CopyTo(incommingHttpContext.Response.Headers);

            // Write the body
            incommingHttpContext.Response.ClearBody();
            
            if (stump.Response.BodyLength > 0)
            {
                var buffer = stump.Response.GetBody();
                if (stump.Response.Headers["Content-Encoding"] != null)
                {
                    var encoder = new ContentEncoder(stump.Response.Headers["Content-Encoding"]);
                    buffer = encoder.Encode(buffer);
                }

                incommingHttpContext.Response.AppendToBody(buffer);
            }

        }