Milestone 1 complete: Kayak removed, HttpListener in place — follow-on clean-up#121
Milestone 1 complete: Kayak removed, HttpListener in place — follow-on clean-up#121
Conversation
… no-op Co-authored-by: hibri <122442+hibri@users.noreply.github.com>
…uestHandlerFactory blank lines Agent-Logs-Url: https://github.com/hibri/HttpMock/sessions/98c11885-a97f-46fd-b392-354806586e77 Co-authored-by: hibri <122442+hibri@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Follow-on cleanup after the Kayak → HttpListener milestone: removes dead code, fixes a file-read correctness issue, and modernizes README sample code.
Changes:
- Update README sample to use
HttpClient.GetStringAsyncwithasync/await, and fix a typo (“Eample” → “Example”). - Remove a no-op
RequestHandlerFactory.ClearHandlers()method. - Replace
FileStream.ReadwithReadExactlyinFileResponseBody.GetBytes()to ensure full-buffer reads.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| README.md | Modernizes sample HTTP call to async HttpClient and fixes a typo. |
| src/HttpMock/RequestHandlerFactory.cs | Removes unused/broken public API method (ClearHandlers). |
| src/HttpMock/FileResponseBody.cs | Uses ReadExactly to avoid partial reads when loading file responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public RequestHandler CustomVerb(string path, string verb) { | ||
| return CreateHandler(path, verb); | ||
| } | ||
|
|
||
| public void ClearHandlers() { | ||
| new List<RequestHandler>(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| private RequestHandler CreateHandler(string path, string method) { |
There was a problem hiding this comment.
Removing the public RequestHandlerFactory.ClearHandlers() method is a breaking change for any external consumers that may be calling it (even if it was previously a no-op). Consider keeping the method as a backwards-compatible wrapper (e.g., delegating to _requestProcessor.ClearHandlers()), marking it [Obsolete], and removing it in the next major version instead of deleting it outright.
| .OK(); | ||
|
|
||
| string result = new WebClient().DownloadString("http://localhost:9191/endpoint"); | ||
| string result = await new HttpClient().GetStringAsync("http://localhost:9191/endpoint"); |
There was a problem hiding this comment.
new HttpClient() is created inline and never disposed in the example. Even in sample code this can encourage patterns that lead to socket exhaustion; prefer a single reused HttpClient instance or a using/using var around it in the snippet.
| string result = await new HttpClient().GetStringAsync("http://localhost:9191/endpoint"); | |
| using var httpClient = new HttpClient(); | |
| string result = await httpClient.GetStringAsync("http://localhost:9191/endpoint"); |
| fileStream.ReadExactly(buffer, 0, (int)fileInfo.Length); | ||
| int length = (int)fileInfo.Length; |
There was a problem hiding this comment.
Since buffer is already sized to the file length, consider calling ReadExactly using buffer.Length (and avoiding repeated (int)fileInfo.Length casts). This removes a potential mismatch if the file size changes between allocation and read, and keeps the code simpler.
| fileStream.ReadExactly(buffer, 0, (int)fileInfo.Length); | |
| int length = (int)fileInfo.Length; | |
| fileStream.ReadExactly(buffer, 0, buffer.Length); | |
| int length = buffer.Length; |
PR #120 fully achieved the first milestone (Kayak →
HttpListener). This PR confirms that and addresses the immediate follow-on hygiene items surfaced during the review.Changes
WebClient.DownloadStringwithHttpClient.GetStringAsync+ async/await; fix "Eample" typoRequestHandlerFactory.ClearHandlers— remove dead no-op that allocated aList<RequestHandler>and discarded it without assigningFileResponseBody.GetBytes— fix CA2022:FileStream.Readcan return fewer bytes than requested; replace withReadExactly(available since .NET 7)Original prompt
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.