private static void SetContent()

in src/Elastic.Transport/Components/TransportClient/HttpRequestInvoker.cs [428:460]


	private static void SetContent(HttpRequestMessage message, BoundConfiguration boundConfiguration, PostData postData)
	{
		if (boundConfiguration.TransferEncodingChunked)
			message.Content = new BoundConfigurationContent(boundConfiguration, postData);
		else
		{
			var stream = boundConfiguration.MemoryStreamFactory.Create();
			if (boundConfiguration.HttpCompression)
			{
				using var zipStream = new GZipStream(stream, CompressionMode.Compress, true);
				postData.Write(zipStream, boundConfiguration.ConnectionSettings, boundConfiguration.DisableDirectStreaming);
			}
			else
				postData.Write(stream, boundConfiguration.ConnectionSettings, boundConfiguration.DisableDirectStreaming);

			// the written bytes are uncompressed, so can only be used when http compression isn't used
			if (boundConfiguration.DisableDirectStreaming && !boundConfiguration.HttpCompression)
			{
				message.Content = new ByteArrayContent(postData.WrittenBytes);
				stream.Dispose();
			}
			else
			{
				stream.Position = 0;
				message.Content = new StreamContent(stream);
			}

			if (boundConfiguration.HttpCompression)
				message.Content.Headers.ContentEncoding.Add("gzip");

			message.Content.Headers.TryAddWithoutValidation("Content-Type", boundConfiguration.ContentType);
		}
	}