Пример #1
0
        public static long GetContentLength(IHttpMessage message, long defaultValue)
        {
            if (message.Headers.TryGet(HttpHeaderNames.ContentLength, out ICharSequence value))
            {
                return(CharUtil.ParseLong(value));
            }

            // We know the content length if it's a Web Socket message even if
            // Content-Length header is missing.
            long webSocketContentLength = GetWebSocketContentLength(message);

            if (webSocketContentLength >= 0)
            {
                return(webSocketContentLength);
            }

            // Otherwise we don't.
            return(defaultValue);
        }
Пример #2
0
        public static long GetContentLength(IHttpMessage message)
        {
            if (message.Headers.TryGet(HttpHeaderNames.ContentLength, out ICharSequence value))
            {
                return(CharUtil.ParseLong(value));
            }

            // We know the content length if it's a Web Socket message even if
            // Content-Length header is missing.
            long webSocketContentLength = GetWebSocketContentLength(message);

            if (webSocketContentLength >= 0)
            {
                return(webSocketContentLength);
            }

            // Otherwise we don't.
            return(ThrowHelper.FromFormatException_HeaderNotFound());
        }