/// <summary> /// Begin encoding headers in the first HEADERS frame. /// </summary> public static bool BeginEncodeHeaders(int statusCode, IEnumerator <KeyValuePair <string, string> > headersEnumerator, Span <byte> buffer, out int length) { if (!HPackEncoder.EncodeStatusHeader(statusCode, buffer, out var statusCodeLength)) { throw new HPackEncodingException(SR.net_http_hpack_encode_failure); } if (!headersEnumerator.MoveNext()) { length = statusCodeLength; return(true); } // We're ok with not throwing if no headers were encoded because we've already encoded the status. // There is a small chance that the header will encode if there is no other content in the next HEADERS frame. var done = EncodeHeaders(headersEnumerator, buffer.Slice(statusCodeLength), throwIfNoneEncoded: false, out var headersLength); length = statusCodeLength + headersLength; return(done); }