Fail after half of the body has been sent #277

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

Originally created by @drauch on GitHub (Jun 23, 2020).

Hi!

We want to simulate in a test that sending the response fails after half of the body has already been sent to the client. The best we could come up with has been:

_server.Given(Request.Create().UsingGet())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK).WithBody(rm => throw new Exception()));
However, this already returns InternalServerError instead of OK to the client. That's not what we want.

How to properly return OK and then fail after a few bytes of the body have been sent?

Best regards,

D.R.

Originally created by @drauch on GitHub (Jun 23, 2020). Hi! We want to simulate in a test that sending the response fails after half of the body has already been sent to the client. The best we could come up with has been: _server.Given(Request.Create().UsingGet()) .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK).WithBody(rm => throw new Exception())); However, this already returns InternalServerError instead of OK to the client. That's not what we want. How to properly return OK and then fail after a few bytes of the body have been sent? Best regards, D.R.
adam added the question label 2025-12-29 15:19:34 +01:00
adam closed this issue 2025-12-29 15:19:34 +01:00
Author
Owner

@StefH commented on GitHub (Jun 23, 2020):

It's not really possible yet to read half of data and return an error.

What you can do is use Faults?
https://github.com/WireMock-Net/WireMock.Net/wiki/Faults

@StefH commented on GitHub (Jun 23, 2020): It's not really possible yet to read half of data and return an error. What you can do is use Faults? https://github.com/WireMock-Net/WireMock.Net/wiki/Faults
Author
Owner

@drauch commented on GitHub (Jun 23, 2020):

Thanks, that should hopefully work for me. Will report back if I run into troubles.

@drauch commented on GitHub (Jun 23, 2020): Thanks, that should hopefully work for me. Will report back if I run into troubles.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#277