Exemple #1
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            if (message is IHttpRequest req)
            {
                if (HttpUtil.Is100ContinueExpected(req))
                {
                    IHttpResponse accept = this.AcceptMessage(req);

                    if (accept == null)
                    {
                        // the expectation failed so we refuse the request.
                        IHttpResponse rejection = this.RejectResponse(req);
                        ReferenceCountUtil.Release(message);
                        context.WriteAndFlushAsync(rejection)
                            .ContinueWith(CloseOnFailure, context, TaskContinuationOptions.ExecuteSynchronously);
                        return;
                    }

                    context.WriteAndFlushAsync(accept)
                        .ContinueWith(CloseOnFailure, context, TaskContinuationOptions.ExecuteSynchronously);
                    req.Headers.Remove(HttpHeaderNames.Expect);
                }
                base.ChannelRead(context, message);
            }
        }
Exemple #2
0
        static object ContinueResponse(IHttpMessage start, int maxContentLength, IChannelPipeline pipeline)
        {
            if (HttpUtil.IsUnsupportedExpectation(start))
            {
                // if the request contains an unsupported expectation, we return 417
                pipeline.FireUserEventTriggered(HttpExpectationFailedEvent.Default);
                return(ExpectationFailed.RetainedDuplicate());
            }
            else if (HttpUtil.Is100ContinueExpected(start))
            {
                // if the request contains 100-continue but the content-length is too large, we return 413
                if (HttpUtil.GetContentLength(start, -1L) <= maxContentLength)
                {
                    return(Continue.RetainedDuplicate());
                }
                pipeline.FireUserEventTriggered(HttpExpectationFailedEvent.Default);
                return(TooLarge.RetainedDuplicate());
            }

            return(null);
        }