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())); } }
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); }
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); }
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); }
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; } }
// =========================================== // instance // =========================================== public Header?HeaderOf(string name) => Headers.HeaderOf(name);
public string HeaderValueOr(string headerName, string defaultValue) => Headers.HeaderOf(headerName)?.Value ?? defaultValue;