natenho / Mockaco

🐵 HTTP mock server, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting
https://natenho.github.io/Mockaco/
Other
335 stars 39 forks source link

Delay attribute won't work in some cases #98

Closed natenho closed 2 years ago

natenho commented 2 years ago

Describe the bug In situations where the client is expecting only the response header, the delay attribute won't take effect.

To Reproduce Given the following template:

{
    "request": {
        "method": "GET"
    },
    "response": {
        "delay": 8000,
        "status": "OK",
        "body": {
            "message": "This should not be received before 8sec"
        }
    }
}

Running curl is enough to notice the behavior: curl -i http://localhost:5000

mockaco-delay-bug

Expected behavior The entire request (including headers) should delay.

Additional context Mockaco delay is processed after all writes are made to the Http Response stream, so any partial chunks would be sent to the client before the response is finished. https://github.com/natenho/Mockaco/blob/0721dfc483cc7dac3a9c3423ab1760973815d84f/src/Mockaco/Middlewares/ResponseDelayMiddleware.cs#L38 https://github.com/natenho/Mockaco/blob/0721dfc483cc7dac3a9c3423ab1760973815d84f/src/Mockaco/Middlewares/ResponseMockingMiddleware.cs#L48