Skip to content

Conversation

@Ref34t
Copy link
Contributor

@Ref34t Ref34t commented Sep 12, 2025

Summary

  • Implements HEAD method support in REST API list controller for performance optimization
  • Returns early with empty response body for HEAD requests while preserving pagination headers
  • Skips expensive data preparation and link generation for HEAD requests

Implementation Details

  • Added HEAD method detection using $request->is_method( 'HEAD' )
  • Preserved X-WP-Total and X-WP-TotalPages headers for both GET and HEAD requests
  • Followed WordPress core patterns from WP_REST_Comments_Controller and WP_REST_Posts_Controller

Testing

  • Added test to verify HEAD requests return empty response body
  • All existing tests continue to pass
  • Code passes PHPCS and PHPStan quality checks

Closes #16

@github-actions
Copy link

github-actions bot commented Sep 12, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @[email protected].

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: [email protected].

Co-authored-by: gziolo <[email protected]>
Co-authored-by: Ref34t <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link

codecov bot commented Sep 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.28%. Comparing base (118c476) to head (06830e3).
⚠️ Report is 1 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk      #71      +/-   ##
============================================
+ Coverage     84.22%   84.28%   +0.06%     
- Complexity       96       97       +1     
============================================
  Files             8        8              
  Lines           507      509       +2     
============================================
+ Hits            427      429       +2     
  Misses           80       80              
Flag Coverage Δ
unit 84.28% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Ref34t
Copy link
Contributor Author

Ref34t commented Sep 12, 2025

@gziolo I've created this PR to resolve #16 as agreed, kindly review and let me know if you have any suggestions

@gziolo gziolo added the [Type] Enhancement New feature or request label Sep 12, 2025
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Thank you for opening the patch. This looks close to go. I left only minor feedback

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Thank you for addressing the feedback.

@gziolo gziolo merged commit 2796a60 into WordPress:trunk Sep 12, 2025
19 checks passed
@Ref34t
Copy link
Contributor Author

Ref34t commented Sep 12, 2025

You're welcome 😁 so fast I didn't have the chance to comment back

@gziolo
Copy link
Member

gziolo commented Sep 12, 2025

Right, I'm reviewing other open PRs today, so I immediately saw the notification 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add HEAD method support for performance optimization in REST API list controller

2 participants