예제 #1
0
        public void StatusInformational()
        {
            EmbeddedChannel channel = new EmbeddedChannel(new HttpResponseEncoder());

            for (int code = 100; code < 200; code++)
            {
                HttpResponseStatus status = HttpResponseStatus.ValueOf(code);
                AssertEmptyResponse(channel, status, null, false);
            }
            Assert.False(channel.Finish());
        }
예제 #2
0
        public void StatusInformationalTransferEncoding()
        {
            EmbeddedChannel channel = new EmbeddedChannel(new HttpResponseEncoder());

            for (int code = 100; code < 200; code++)
            {
                HttpResponseStatus status = HttpResponseStatus.ValueOf(code);
                AssertEmptyResponse(channel, status, HttpHeaderNames.TransferEncoding, code != 101);
            }
            Assert.False(channel.Finish());
        }
예제 #3
0
        protected override void Encode(IChannelHandlerContext ctx, IResponseMessage msg, List <object> output)
        {
            var buf      = msg.ToBodyBuffer();
            var status   = HttpResponseStatus.ValueOf(Convert.ToInt32(msg.Headers.Get(Constants.ResponseStatusCode)));
            var response = new DefaultFullHttpResponse(HttpVersion.Http11, status, buf, false);

            HttpHeaders headers = response.Headers;

            headers.Set(HttpHeaderNames.Server, AsciiString.Cached(Options.Name));
            headers.Set(HttpHeaderNames.Date, this.date);
            headers.Set(HttpHeaderNames.ContentLength, AsciiString.Cached($"{msg.Headers.Get(Constants.Headers.ContentLength)}"));

            if (Convert.ToInt32(msg.Headers.Get(Constants.Headers.ContractId)) == (int)ContractType.HandShake)
            {
                headers.Set(HttpHeaderNames.ContentType, AsciiString.Cached("text/plain"));
            }
            else
            {
                headers.Set(HttpHeaderNames.ContentType, AsciiString.Cached(msg.Headers.Get(Constants.Headers.ContentType)));
            }
            output.Add(response);
        }