Skip to content

Fix Keep-Alive Chrome Issue & add request header payload reading

Choose a tag to compare

@hempe hempe released this 04 Sep 13:25
· 8 commits to master since this release
8e2f3f8
Fix/http method validation (#15)

* Improve HTTP method validation and error responses

- Add proper HTTP method validation for WebSocket handshakes (return 405 for non-GET)
- Add Connection header validation for WebSocket handshakes (return 400 for missing/invalid)
- Add GET method validation to FileResponse methods (return 405 for non-GET)
- Remove unused ValidateWebSocketHandshakeRequest method
- Replace exception throwing with proper HTTP error responses

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add extension methods and update demo to use new file response methods

- Add CreateFileResponse and CreateEmbeddedResourceResponse extension methods
- Update demo server to use new extension methods with proper validation
- Minor formatting improvements

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add HTTP keep-alive connection management and Date header support

- Add KeepAliveTimeout and MaxKeepAliveConnections to WebSocketServerOptions
- Implement LRU eviction for keep-alive connections when limits are reached
- Add automatic Date header to all HTTP responses (RFC 7231 compliance)
- Refactor ProcessTcpClientAsync with proper connection lifecycle management
- WebSocket upgrades properly remove connections from keep-alive tracking
- Add comprehensive keep-alive tests with Theory-based parameterization
- Refactor HttpResponse to eliminate code duplication in header writing
- Update WebSocketServerBuilder with new keep-alive configuration methods
- Add authentication examples to demo applications

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fixes

* Improve HTTP request body reading and keep-alive functionality

- Fix HTTP request body reading by using byte-by-byte header parsing to prevent over-reading
- Add Keep-Alive header with timeout value in HTTP responses
- Change default KeepAliveTimeout from 30s to 5s for more responsive connection management
- Simplify keep-alive connection tracking using FIFO ConcurrentQueue instead of timestamp-based eviction
- Move default values from constructor to property declarations for single source of truth
- Update documentation to reflect new 5-second default

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Improve keep-alive timeout behavior to only apply to idle connection detection

- Keep-alive timeout now only applies to first byte read (detecting idle connections)
- Once data starts flowing, timeout is removed for rest of request/body reading
- Fix connection eviction to only remove one connection instead of draining queue
- Add thread safety for CancellationTokenSource disposal during eviction
- Move logging calls to proper Events.cs with structured logging
- Rename RegisterKeepAliveConnection to ManageKeepAliveConnectionLimit for clarity

This resolves issues where slow but active connections were incorrectly timed out
during request body reading, while still protecting against truly idle connections.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Update documentation to reflect improved keep-alive timeout behavior

- Clarify that KeepAliveTimeout only applies to first-byte detection
- Update README and code comments to explain timeout doesn't affect active transfers
- Improve parameter descriptions in WebSocketServerBuilder

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Simplify timeout exception handling in HttpHeader

- Remove redundant timeout-specific exception handling
- Let general catch block handle cleanup for all exceptions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Remove Stopwatch

* new "new()"

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: hub@bica.ch <hub@bica.ch>