How to mock a download limit when downloading a file? #348

Closed
opened 2025-12-29 15:21:28 +01:00 by adam · 2 comments
Owner

Originally created by @JasonLandbridge on GitHub (May 15, 2021).

Originally assigned to: @StefH on GitHub.

Given the following code:

var _server = WireMockServer.Start();      
_server
    .Given(Request.Create().WithPath("media/file.avi").UsingGet())
    .RespondWith(
        Response.Create()
            .WithStatusCode(206)
            .WithBodyFromFile("media/file.avi")
    );

File downloads fine but It goes extremely fast as it is read from SSD into a memory stream. How can I make the download go slower as to mimic real life scenario?

Thanks in advance!

Originally created by @JasonLandbridge on GitHub (May 15, 2021). Originally assigned to: @StefH on GitHub. Given the following code: ``` c# var _server = WireMockServer.Start(); _server .Given(Request.Create().WithPath("media/file.avi").UsingGet()) .RespondWith( Response.Create() .WithStatusCode(206) .WithBodyFromFile("media/file.avi") ); ``` File downloads fine but It goes extremely fast as it is read from SSD into a memory stream. How can I make the download go slower as to mimic real life scenario? Thanks in advance!
adam added the question label 2025-12-29 15:21:28 +01:00
adam closed this issue 2025-12-29 15:21:28 +01:00
Author
Owner

@StefH commented on GitHub (May 16, 2021):

Hello @JasonLandbridge,

As workaround, you can implement your own version from IFileSystemHandler.

See https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#filesystemhandler for details.

@StefH commented on GitHub (May 16, 2021): Hello @JasonLandbridge, As workaround, you can implement your own version from `IFileSystemHandler`. See https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#filesystemhandler for details.
Author
Owner

@JasonLandbridge commented on GitHub (May 16, 2021):

@StefH, thanks for the answer!

I went a different route, I implemented a download limiter stream as explained here: stackoverflow

And now I can use that in my unit tests, which works perfectly with WireMock!

Also, thank you very much for all your work on WireMock.Net!

(Lekker bezig pik 💯 )

@JasonLandbridge commented on GitHub (May 16, 2021): @StefH, thanks for the answer! I went a different route, I implemented a download limiter stream as explained here: [stackoverflow](https://stackoverflow.com/questions/32723561/bandwidth-throttling/32724000#32724000) And now I can use that in my unit tests, which works perfectly with WireMock! Also, thank you very much for all your work on WireMock.Net! (Lekker bezig pik 💯 )
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#348