<commit_before>using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace TypedRest.Endpoints.Raw
{
    /// <summary>
    /// Endpoint that accepts binary uploads.
    /// </summary>
    public class UploadEndpoint : EndpointBase, IUploadEndpoint
    {
        private readonly string? _formField;

        /// <summary>
        /// Creates a new upload endpoint using raw bodies.
        /// </summary>
        /// <param name="referrer">The endpoint used to navigate to this one.</param>
        /// <param name="relativeUri">The URI of this endpoint relative to the <paramref name="referrer"/>'s.</param>
        public UploadEndpoint(IEndpoint referrer, Uri relativeUri)
            : base(referrer, relativeUri)
        {}

        /// <summary>
        /// Creates a new upload endpoint using multi-part form encoding.
        /// </summary>
        /// <param name="referrer">The endpoint used to navigate to this one.</param>
        /// <param name="relativeUri">The URI of this endpoint relative to the <paramref name="referrer"/>'s.</param>
        /// <param name="formField">The name of the form field to place the uploaded data into.</param>
        public UploadEndpoint(IEndpoint referrer, Uri relativeUri, string formField)
            : this(referrer, relativeUri)
        {
            _formField = formField;
        }

        /// <summary>
        /// Creates a new upload endpoint using raw bodies.
        /// </summary>
        /// <param name="referrer">The endpoint used to navigate to this one.</param>
        /// <param name="relativeUri">The URI of this endpoint relative to the <paramref name="referrer"/>'s. Prefix <c>./</c> to append a trailing slash to the <paramref name="referrer"/> URI if missing.</param>
        public UploadEndpoint(IEndpoint referrer, string relativeUri)
            : base(referrer, relativeUri)
        { }

        /// <summary>
        /// Creates a new upload endpoint using multi-part form encoding.
        /// </summary>
        /// <param name="referrer">The endpoint used to navigate to this one.</param>
        /// <param name="relativeUri">The URI of this endpoint relative to the <paramref name="referrer"/>'s.</param>
        /// <param name="formField">The name of the form field to place the uploaded data into.</param>
        public UploadEndpoint(IEndpoint referrer, string relativeUri, string formField)
            : this(referrer, relativeUri)
        {
            _formField = formField;
        }

        public Task UploadFromAsync(Stream stream, string? fileName = null, string? mimeType = null, CancellationToken cancellationToken = default)
        {
            HttpContent content = new StreamContent(stream);
            if (!string.IsNullOrEmpty(mimeType)) content.Headers.ContentType = MediaTypeHeaderValue.Parse(mimeType);

            if (!string.IsNullOrEmpty(_formField))<commit_msg>Simplified UploadEndpoint constructors using optional parameters<commit_after>using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace TypedRest.Endpoints.Raw
{
    /// <summary>
    /// Endpoint that accepts binary uploads using multi-part form encoding or raw bodies.
    /// </summary>
    public class UploadEndpoint : EndpointBase, IUploadEndpoint
    {
        private readonly string? _formField;

        /// <summary>
        /// Creates a new upload endpoint.
        /// </summary>
        /// <param name="referrer">The endpoint used to navigate to this one.</param>
        /// <param name="relativeUri">The URI of this endpoint relative to the <paramref name="referrer"/>'s.</param>
        /// <param name="formField">The name of the form field to place the uploaded data into; leave <c>null</c> to use raw bodies instead of a multi-part forms.</param>
        public UploadEndpoint(IEndpoint referrer, Uri relativeUri, string? formField = null)
            : base(referrer, relativeUri)
        {
            _formField = formField;
        }

        /// <summary>
        /// Creates a new upload endpoint using multi-part form encoding.
        /// </summary>
        /// <param name="referrer">The endpoint used to navigate to this one.</param>
        /// <param name="relativeUri">The URI of this endpoint relative to the <paramref name="referrer"/>'s.</param>
        /// <param name="formField">The name of the form field to place the uploaded data into; leave <c>null</c> to use raw bodies instead of a multi-part forms.</param>
        public UploadEndpoint(IEndpoint referrer, string relativeUri, string? formField = null)
            : base(referrer, relativeUri)
        {
            _formField = formField;
        }

        public Task UploadFromAsync(Stream stream, string? fileName = null, string? mimeType = null, CancellationToken cancellationToken = default)
        {
            HttpContent content = new StreamContent(stream);
            if (!string.IsNullOrEmpty(mimeType)) content.Headers.ContentType = MediaTypeHeaderValue.Parse(mimeType);

            if (!string.IsNullOrEmpty(_formField))
{'fraction_non_alphanumeric': 0.11072664359861592, 'fraction_numerical': 0.0, 'mean_word_length': 2.620737647877523, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2641884', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1341, 'n_words': 445}