codesenberg / bombardier

Fast cross-platform HTTP benchmarking tool written in Go
MIT License
6k stars 313 forks source link

auto calculated boundary in large file uploading in asp.net core and testing with bombardier #99

Open Amit-limbasiya opened 1 year ago

Amit-limbasiya commented 1 year ago

What version of bombardier are you using?

Hash of the commit, like

00d7965d6cae34c62042abb0f6c45c45b870dcf3

What operating system and processor architecture are you using (if relevant)?

windows/amd64

What did you do?

i have written a code in asp.net core in minimal api as:

app.MapPost("/uploadFile", async (HttpContext context) => {

    string[] permittedExtensions = { ".pdf", ".bin", ".txt" };
    var boundary = HeaderUtilities.RemoveQuotes(MediaTypeHeaderValue
        .Parse(context.Request.ContentType).Boundary).Value;
    var reader = new MultipartReader(boundary, context.Request.Body, 524288000);
    var section = await reader.ReadNextSectionAsync();
    while (section != null)
    {
        if (ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition))
        {
            var fileExt = Path.GetExtension(contentDisposition.FileName.Value);
            if (string.IsNullOrEmpty(fileExt) || !permittedExtensions.Contains(fileExt) || !permittedExtensions.Contains(fileExt.ToLower()))
            {
                return Results.Problem(statusCode:415,title:"Invalid Extension");
            }
            if (contentDisposition.FileName.HasValue)
            {
                var fileName = Guid.NewGuid().ToString()+ contentDisposition.FileName.Value;
                using (var stream = new FileStream(Path.Combine(Path.GetTempPath(),fileName), FileMode.Create))
                {
                    await section.Body.CopyToAsync(stream);
                }
            }
        }
        section = await reader.ReadNextSectionAsync();
    }
    return Results.Ok("File uploaded successfully."); 
});

i had configure for max. 500mb size as

builder.Services.Configure<KestrelServerOptions>(options =>
{
    options.Limits.MaxRequestBodySize = 524288000;
});
builder.Services.Configure<FormOptions>(options =>
{
    options.MultipartHeadersLengthLimit = 524288000;
    options.MultipartBoundaryLengthLimit = 524288000;
    options.MultipartBodyLengthLimit = 524288000;
    options.ValueLengthLimit = 524288000;
    options.BufferBodyLengthLimit = 524288000;
}
);

What actually happened?

when i tried to sent the request from postman it has header conf. like Content-Type: multipart/form-data; boundary= Content-Length: Host:

and it will upload the file successfully at temp folder.

but when i tried it with bombardier as: bombardier -c 1 -n 1 -m POST --header="Content-Type: multipart/form-data; boundary= " --header="Content-Length:524288000" -f "Report.pdf" "https://localhost:7246/uploadFile" --http1.

it is not working and gives error like The header contains invalid values at index 0: 'multipart/form-data; boundary= '

how to solve this problem? basically, I am taking the pdf file as an input from user and wants to upload at my temp.folder and when i run on postman it will take random boundary automatically, how to made it work on bombardier that it will take random boundary and upload fle as postman.

codesenberg commented 1 year ago

Another user previously encountered similar issue in #21. In short, currently you'll have to craft the body yourself. It should be possible to implement a feature that would provide something similar to what cURL offers.

Amit-limbasiya commented 1 year ago

thanks @codesenberg, just need one confirmation for what i have understood, currently i have to craft body manually to use bombardier but curl set auto-boundary and wrap the content of file with the boundary. right?

codesenberg commented 1 year ago

That's right.