Skip to content

Conversation

@fwfurtado
Copy link
Contributor

This pull request introduces support for the HTTP HEAD method across various endpoints and structures in the codebase. It ensures that HEAD requests are properly handled in both core functionality and examples, while also updating related authentication and middleware logic.

Support for HEAD method in endpoints:

  • Added head method to multiple endpoint structs, including MyEndpoint, SimpleEndpoint, ErrorEndpoint, StopEndpoint, HtmlEndpoint, and UserWeb, enabling them to handle HEAD requests. ([[1]](https://github.com/zigzap/zap/pull/164/files#diff-146a459eb4ae8d10d2699ccb000c4f6a750d9a8bd4c25290d0b212db3f74dec3R68), [[2]](https://github.com/zigzap/zap/pull/164/files#diff-3bdafe3135ec8926afcba258bffc5ebacb513f1a41b508e91f6bbaf0b40aad10R69), [[3]](https://github.com/zigzap/zap/pull/164/files#diff-76e6ff01f25c8c789cc21480ddc2b2e0418780e50a9ae5f14041199c079c7faeR56), [[4]](https://github.com/zigzap/zap/pull/164/files#diff-a5c3f42c7324c64cc8830efcb8822a1ada8540d9d66135f67b2cf97fb58c103dR26), [[5]](https://github.com/zigzap/zap/pull/164/files#diff-ba39abdb36f2a4f6fc4ec388f86acb13dbc342d7f9aeca599550e4dd60271242R160), [[6]](https://github.com/zigzap/zap/pull/164/files#diff-cd028a11497e4e351d65564f1915f763908f20bacf6587b88a83064585cc508cL130-R135))
  • Updated UserWeb's options method to include HEAD in the Access-Control-Allow-Methods header. ([examples/endpoint/userweb.zigL130-R135](https://github.com/zigzap/zap/pull/164/files#diff-cd028a11497e4e351d65564f1915f763908f20bacf6587b88a83064585cc508cL130-R135))

Core framework updates for HEAD method:

  • Modified src/App.zig to route HEAD requests to the appropriate head method in the endpoint. ([src/App.zigR120](https://github.com/zigzap/zap/pull/164/files#diff-aa9d26de9c6c82b2d1d0829bdd7b5c6bf4b8ce3968b9079121806eea654e1f25R120))
  • Added head to the list of supported HTTP methods in src/App.zig. ([src/App.zigR177](https://github.com/zigzap/zap/pull/164/files#diff-aa9d26de9c6c82b2d1d0829bdd7b5c6bf4b8ce3968b9079121806eea654e1f25R177))
  • Introduced authentication logic for HEAD requests in src/App.zig and src/endpoint.zig, ensuring proper handling of authenticated HEAD requests. ([[1]](https://github.com/zigzap/zap/pull/164/files#diff-aa9d26de9c6c82b2d1d0829bdd7b5c6bf4b8ce3968b9079121806eea654e1f25R310-R318), [[2]](https://github.com/zigzap/zap/pull/164/files#diff-b6751b13bfcd4e31d24370fa695d8d43f27d86397e31e166572047b340cec172R302-R310))

Documentation and validation updates:

  • Updated comments and validation logic in src/endpoint.zig to include the head method. ([[1]](https://github.com/zigzap/zap/pull/164/files#diff-b6751b13bfcd4e31d24370fa695d8d43f27d86397e31e166572047b340cec172R22), [[2]](https://github.com/zigzap/zap/pull/164/files#diff-b6751b13bfcd4e31d24370fa695d8d43f27d86397e31e166572047b340cec172R53), [[3]](https://github.com/zigzap/zap/pull/164/files#diff-b6751b13bfcd4e31d24370fa695d8d43f27d86397e31e166572047b340cec172R102))

Middleware and testing:

  • Enhanced middleware in src/middleware.zig to process HEAD requests. ([src/middleware.zigR112](https://github.com/zigzap/zap/pull/164/files#diff-96eb9e5cbd3c1ba3aac8e9cf89868e6309f0ef17e40bcf0dd85ff3b21cc9482cR112))
  • Added head method to the test Endpoint struct in src/tests/test_auth.zig to ensure test coverage for HEAD requests. ([src/tests/test_auth.zigR173](https://github.com/zigzap/zap/pull/164/files#diff-a2d4c702afe4c486e4acb56e8d068fb5e989c8c53fb0f610fe361655d325d7b0R173))

@renerocksai
Copy link
Member

Thanks! Also for the review! I will merge without smoke-testing. This looks well put-together.

BTW I also noticed while playing with the XXX branch that head was missing; BTW BTW the XXX branch contains experiments to introduce sort-of vtables to remove the requirement to empty-implement unused method handlers. I'm going back and forth with it. And it's on hold right now because work interfered. but if possible, I want to make it work. the drawback from my current perspective: it adds one more layer of indirection.

@renerocksai renerocksai merged commit ec7cac6 into zigzap:master Apr 22, 2025
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.

3 participants