Skip to content

Conversation

@softko
Copy link

@softko softko commented Dec 14, 2025

Summary

Optimize HEAD requests for the stats endpoint by skipping response body generation and transmission while maintaining full functionality for GET requests.

Changes

  • Add http_method field to connection structure to store HTTP method
  • Store HTTP method during request processing for later use in stats handling
  • Skip response body generation and transmission for HEAD requests to stats endpoint
  • Maintain backward compatibility for all existing GET request functionality

Benefits

  • Reduced I/O overhead: HEAD requests no longer read stats template files unnecessarily
  • Reduced network traffic: No response body transmitted for HEAD requests
  • Improved RFC compliance: Proper HEAD method semantics (headers without body)
  • Zero performance impact: No overhead for existing GET requests
  • Full backward compatibility: All existing functionality preserved

Testing

  • Verified successful compilation with no warnings
  • Confirmed HEAD vs GET request detection logic works correctly
  • All existing functionality remains unchanged

This addresses the performance optimization opportunity where HEAD requests were previously processing and sending the full response body unnecessarily.

- Add http_method field to connection structure to store HTTP method
- Store HTTP method during request processing for later use
- Skip response body generation and transmission for HEAD requests to stats endpoint
- Maintain full functionality for GET requests
- Reduces I/O overhead and network traffic for HEAD requests
- Improves RFC compliance by properly handling HEAD method semantics

This change ensures HEAD requests to the stats endpoint return appropriate
headers without the response body, reducing unnecessary file I/O and network
overhead while maintaining backward compatibility.
src/conns.h Outdated
char *request_line;

/* The HTTP method from the request line */
char *http_method;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's inefficient and error-prone to use heap-allocated strings to store a single boolean flag "is_head_method". if we cared about the method type elsewhere, we could use "enum http_method" but since we don't that would be overkill for the moment. so just use an int or char set to TRUE or FALSE like we do elsewhere in order not to pull in dependencies on stdbool.h.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your feedback, also changed the returning headers sooner to avoid stats file processing at all

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