Skip to content

Fix multiple bugs: null checks, header case-sensitivity, async patterns, test assertions - #18

Draft
daohainam with Copilot wants to merge 1 commit into
masterfrom
copilot/review-and-fix-bugs
Draft

Fix multiple bugs: null checks, header case-sensitivity, async patterns, test assertions#18
daohainam with Copilot wants to merge 1 commit into
masterfrom
copilot/review-and-fix-bugs

Conversation

Copilot AI commented May 31, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes several bugs identified through code review of the codebase.

Changes

1. Fix ArgumentNullException.ThrowIfNull(nameof(x)) — always a no-op

Files: HttpResponseHeaders.cs, Http2FrameWriter.cs, MvcMiddleware.cs, Controller.cs

ThrowIfNull(nameof(value)) passes the string literal "value" which is never null — making the check useless. Fixed to pass the actual variable.

2. Fix test assertion argument order (expected/actual swapped)

File: ReadRequestTests.cs

Assert.AreEqual(actual, expected) produces misleading failure messages. Fixed to Assert.AreEqual(expected, actual).

3. Fix HttpHeaders.Remove crashes when header doesn't exist

File: HttpHeaders.cs

FindIndex returns -1 when not found, but the code directly indexed headers[-1], causing IndexOutOfRangeException. Added bounds check.

4. Fix case-sensitive header name comparisons

File: HttpHeaders.cs

HTTP headers are case-insensitive per RFC 7230. AddOrUpdate, AddOrSkip, and Remove used == for comparison. Fixed to use StringComparison.OrdinalIgnoreCase (consistent with the existing TryGetValue method).

5. Fix wrong exception type in MultipartFormDataFormReader

File: MultipartFormDataFormReader.cs

Was throwing NullReferenceException (a runtime-only exception) for invalid state. Changed to InvalidOperationException which correctly signals programmer error.

6. Fix Task.WaitAll blocking in async context

File: MiniWebClientConnection.cs

Replaced synchronous Task.WaitAll() with await Task.WhenAll() to prevent thread pool starvation and potential deadlocks in async methods.

…ion order, HttpHeaders case-sensitivity and bounds check, Task.WaitAll in async context, wrong exception type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants