Exemple #1
0
        private void AddMissingContentLengthHeader()
        {
            var contentLength = Entity.Content.Length;
            var header        = Headers.HeaderOf(ResponseHeader.ContentLength);

            if (header == null)
            {
                Headers.Add(ResponseHeader.Of(ResponseHeader.ContentLength, contentLength.ToString()));
            }
        }
Exemple #2
0
        private Headers <ResponseHeader> AddMissingContentLengthHeader(Headers <ResponseHeader> headers)
        {
            if (!Entity.IsComplex)
            {
                var header = headers.HeaderOf(ResponseHeader.ContentLength);
                if (header == null && !((int)Status).ToString().StartsWith("1") && Status != ResponseStatus.NoContent && Status != ResponseStatus.NotModified)
                {
                    headers.Add(ResponseHeader.Of(ResponseHeader.ContentLength, Entity.Content.Length));
                }
            }

            return(headers);
        }
Exemple #3
0
        private Body EntityFrom(Headers <ResponseHeader> headers, Body entity)
        {
            var header = headers.HeaderOf(ResponseHeader.TransferEncoding);

            if (header != null && header.Value !.Equals("chunked"))
            {
                if (entity.IsComplex && !entity.HasContent)
                {
                    return(Body.BeginChunked());
                }
            }

            return(entity);
        }
Exemple #4
0
        private Headers <ResponseHeader> AddMissingContentLengthHeader(Headers <ResponseHeader> headers)
        {
            if (!Entity.IsComplex)
            {
                var contentLength = Entity.Content.Length;
                var header        = headers.HeaderOf(ResponseHeader.ContentLength);
                if (header == null && contentLength > 0)
                {
                    headers.Add(ResponseHeader.Of(ResponseHeader.ContentLength, contentLength));
                }
            }

            return(headers);
        }
Exemple #5
0
        internal Request(Method method, Uri uri, Version version, Headers <RequestHeader> headers, Body body)
        {
            Method  = method;
            Uri     = uri;
            Version = version;
            Body    = body;

            if (body != null && body.HasContent && headers.HeaderOf("Content-Length") == null)
            {
                Headers = headers.And("Content-Length", $"{body.Content.Length}");
            }
            else
            {
                Headers = headers;
            }
        }
Exemple #6
0
        // ===========================================
        // instance
        // ===========================================

        public Header?HeaderOf(string name) => Headers.HeaderOf(name);
Exemple #7
0
 public string HeaderValueOr(string headerName, string defaultValue)
 => Headers.HeaderOf(headerName)?.Value ?? defaultValue;