Fix Func<string> response body being invoked twice per request#128
Merged
Fix Func<string> response body being invoked twice per request#128
Conversation
Agent-Logs-Url: https://github.com/hibri/HttpMock/sessions/5f869925-f118-4ca0-b6ed-8b784ee10e42 Co-authored-by: hibri <122442+hibri@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix request handler invoking twice issue
Fix Func<string> response body being invoked twice per request
Apr 16, 2026
Agent-Logs-Url: https://github.com/hibri/HttpMock/sessions/8ccb2e78-3d8d-4ec2-a086-3c75df01f2a5 Co-authored-by: hibri <122442+hibri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hibri/HttpMock/sessions/d7e896f4-32bf-4935-8f8e-3e8064d274d7 Co-authored-by: hibri <122442+hibri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hibri/HttpMock/sessions/e792ed95-fb24-4f17-907b-292a856f5601 Co-authored-by: hibri <122442+hibri@users.noreply.github.com>
hibri
reviewed
Apr 16, 2026
| } | ||
|
|
||
| public HttpMockResponseHead BuildHeaders() { | ||
| public HttpMockResponseHead BuildHeaders(byte[] body = null) { |
Owner
There was a problem hiding this comment.
@copilot Do not pass the whole body in here as only the content length is needed.
Contributor
Author
There was a problem hiding this comment.
Done in 125e59a. BuildHeaders now accepts int? contentLength = null and the call site passes responseBody?.Length — only the length crosses the boundary, not the body bytes.
hibri
reviewed
Apr 16, 2026
|
|
||
| var responseHead = handler.ResponseBuilder.BuildHeaders(); | ||
| var responseHead = handler.ResponseBuilder.BuildHeaders(responseBody); | ||
| var statusCode = responseHead.Status?.Split(' ') is { Length: > 0 } parts ? parts[0] : null; |
Owner
There was a problem hiding this comment.
@copilot This line of code is hard to read, keep the code readable
Contributor
Author
There was a problem hiding this comment.
Fixed in 6c9c1ab. The one-liner is now split into two steps:
var statusParts = responseHead.Status?.Split(' ');
var statusCode = statusParts is { Length: > 0 } ? statusParts[0] : null;…bytes Agent-Logs-Url: https://github.com/hibri/HttpMock/sessions/253a6002-9bf9-4f6a-9df4-e7c01e57e8f7 Co-authored-by: hibri <122442+hibri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hibri/HttpMock/sessions/e74af7ca-4f57-4385-bd6e-9b3a3b68bcc6 Co-authored-by: hibri <122442+hibri@users.noreply.github.com>
hibri
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ResponseBuilder.BuildHeaders(int? contentLength = null)— accept only the pre-computed content length to deriveContent-LengthviacontentLength ?? _contentLength(), removing all shared stateRequestProcessor.HandleRequestto passresponseBody?.LengthtoBuildHeaders