Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.59k stars 798 forks source link

Enhancement: Support retrieving request headers passed through the Jetpack bridge #40181

Open iamgabrielma opened 2 days ago

iamgabrielma commented 2 days ago

Impacted plugin

Jetpack

What

Add support for retrieving X-WP-Total and X-WP-TotalPages for Jetpack-tunnelled requests.

How

Some Woo core endpoints include useful data in the response headers, for example X-WP-Total and X-WP-TotalPages which we can use for pagination. However, when using a Jetpack-tunnelled request, these headers are removed from the response.

As specific example for the WooCommerce app, when we make a request to wc/v3/products the response includes a X-WP-Total header that tells us how many total results are for a query regardless of the value of per_page that we submit, this is key for implement proper pagination, but we're only able to make it work for non-Jetpack connected sites.

Similar fixes were done for the wp/v2/ API, where WPCOM API v2 proxied responses from remote Jetpack sites were missing the pagination headers: p9dueE-5ZK-p2

This has posed a challenge in several projects, and while we worked around them with different hacks in place, it's definitely not optimal and prone to error. As an example:

jeherve commented 2 days ago

Related conversation: p1731567884525159-slack-CDLH4C1UZ

I think it could be useful to p2 about this on +jetpackvulcan, with an example of how one can make a request to wc/v3/products when not using the Jetpack plugin, and when using the Jetpack plugin (or is it not dependent on the Jetpack plugin but instead depends on the connection to WordPress.com via the Jetpack Connection package that ships with the WooCommerce plugin?).