| 开发者 | bluefairydevelopment |
|---|---|
| 更新时间 | 2026年11月30日 02:41 |
| 捐献地址: | 去捐款 |
| PHP版本: | 8.1 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
GET responses are stored and served back with an X-BF-Cache: HIT header; every REST response is labelled HIT, MISS or BYPASS so you can see the decision from curl. Requests from logged-in users, or carrying an Authorization, X-WP-Nonce or X-BF-API-Key header, are never cached. Responses that are not 2xx, that stream, that set a cookie or whose Cache-Control says no-store, private, no-cache or max-age=0 are never stored. Up to 500 cache rules, each matched by route glob (wp/v2/posts/** — a trailing /** or /* matches the collection route too) with its own lifetime; the most specific matching rule wins, and one is seeded on activation as "all routes, 60 seconds". The cache is purged automatically when a post, term or comment changes, and by hand from the Cache tab or POST /bfag/v1/cache/purge. Responses live in your persistent object cache (Redis, Memcached) when you have one, otherwise in transients — capped there at 64 KB per response and one hour, and swept every five minutes.
Rate limiting. A sliding-window counter per client IP and rule (an IPv6 client is counted by its /64 network, so rotating addresses within it does not escape the limit). The breaching request gets 429 Too Many Requests with Retry-After, X-BF-RateLimit-Limit and X-BF-RateLimit-Window. Up to 500 rules, each counting the routes its glob matches; one is seeded as 300 requests per 60 seconds across every route, and logged-in users who can edit posts are exempt by default in their own browser session (requests made with an API key or an application password are always limited). One forwarded-IP header of your choosing (X-Forwarded-For by default; CF-Connecting-IP, X-Real-IP or True-Client-IP) is honoured, and only from the proxy ranges you list, so a visitor cannot pick their own bucket. A client over the limit is refused from a marker for the rest of its window without touching the database; with a persistent object cache the count itself is an atomic increment rather than a query. The hit log is pruned every five minutes.
Signed outbound webhooks. Up to 500 webhooks, each subscribing to one event: post published, updated or deleted; user registered or updated; comment created; and, with WooCommerce, order created, order status changed, order completed, product updated. Each delivery is a JSON POST carrying X-BF-Event, X-BF-Delivery, X-BF-Timestamp and X-BF-Signature: sha256=HMAC-SHA256(timestamp.body, secret), so the receiver can verify both origin and freshness. Deliveries are collected during the request and sent once after the response — twenty at most, and for fifteen seconds at most, the rest through a WP-Cron event so a bulk import or a dead endpoint never ties up the request that saved it — logged with their HTTP status and response body, and any failed delivery can be resent from the log. Targets must be https://; a secret is generated for you and shown once, right after saving, for you to copy into the receiver.
Dashboard. Cache hit rate and webhook success rate over the last 24 hours, the current size of the rate-limit log, the ten most recent failed deliveries with a Retry button, and the same figures at GET /bfag/v1/status for a monitoring tool — a route that is never rate-limited.
Add API Gateway Pro for purges narrowed to the tags a change touches; rate limits per user and per API key with penalty blocks; DDoS auto-block with a blocked-IPs panel; automatic webhook retries with back-off and failure alerts by email; Salesforce, HubSpot and Mailchimp presets; a verified incoming-webhook endpoint (HubSpot signed; Salesforce and Mailchimp shared secret); a webhook REST API; API keys with scopes; and WPGraphQL query caching. Pro installs alongside this plugin rather than replacing it.
Documentation and testing
Tested with WordPress 7.1 on 2026-10-29: run end to end in a real browser on a clean WordPress 7.1 site with WooCommerce, Plugin Check and the Twenty Twenty-Five theme.
bluefairy-api-gateway folder to /wp-content/plugins/, or install the zip from Plugins → Add New → Upload Plugin.bfag_manage_gateway capability to administrators and schedules four recurring WP-Cron jobs. The cache and the rate limiter are on from the first request; nothing is sent anywhere until you add a webhook.BYPASS means the request or the response was not cacheable. On the request side: the cache is switched off; the method is not GET or HEAD; you are logged in (a browser with a WordPress cookie, including the admin's own browser); the request carries an Authorization, X-WP-Nonce or X-BF-API-Key header; the route is under /bfag/v1; or no enabled cache rule matches the route. On the response side: the status is not 2xx; the response streams (text/event-stream); it sets a cookie (including through PHP's setcookie(), as WooCommerce's guest cart session does — a plugin that sets a cookie on every request keeps responses from being stored); or its Cache-Control says no-store, private, no-cache or max-age=0. Test with curl from a fresh shell, not from a logged-in browser tab.
Yes. With a persistent object cache responses are stored in the object-cache group bfag_responses; without one they are stored as transients in the options table — capped at 64 KB per response and one hour, with expired entries swept every five minutes — and purging works the same way on both. A persistent object cache is faster, has no size cap, keeps the options table small and turns the rate-limit count and the cache statistics into in-memory increments, so use one on a busy site.
By default the client IP is REMOTE_ADDR, which behind a proxy is the proxy's own address — so every visitor would share one rate-limit bucket. List the proxy's addresses or CIDR ranges under Settings → Rate limit → Trusted proxies (for Cloudflare, its published IP ranges) and pick the Client address header your proxy writes (X-Forwarded-For by default; for Cloudflare, CF-Connecting-IP). Only when REMOTE_ADDR is inside one of those ranges is that one header read — for X-Forwarded-For, taking the right-most address that is not itself a trusted proxy. Every other header, and headers from anywhere else, are ignored, so a visitor cannot forge their way into a different bucket, not even by adding an X-Real-IP of their own in front of a proxy that only manages X-Forwarded-For.
Deleting the plugin always removes its options, transients, cron events and the bfag_manage_gateway capability. Your rules, webhooks and delivery log — the six bfag_ database tables — are dropped only if you ticked Delete data on uninstall under Settings → Advanced first. By default they stay, because a delivery log is a record of what was sent, not a cache. Deactivating removes only the cron events and the capability.
In the free plugin a failed delivery — any non-2xx answer, or no answer within five seconds — is marked failed in the log and stays there. Press Retry — offered on failed deliveries only — on the dashboard or in the delivery log to resend the stored payload bytes as the next attempt, with a fresh timestamp and signature and the same X-BF-Delivery id. A delivery whose stored payload was truncated at the Max stored payload setting cannot be retried, because the stored bytes are no longer what was signed. Automatic retries with back-off (one minute, five minutes, thirty minutes, up to a per-webhook limit) and failure alerts are part of API Gateway Pro.
Compute HMAC-SHA256 with the webhook's secret over the string X-BF-Timestamp + "." + raw request body, hex-encode it, prefix sha256=, and compare it to X-BF-Signature in constant time (hash_equals() in PHP, crypto.timingSafeEqual() in Node). Read the raw body bytes before any framework parses them. Reject timestamps more than a few minutes old to defeat replay. Full PHP and Node examples are in the features guide shipped with the plugin, docs/ApiGatewayFeaturesGuide.pdf, under Webhooks → Verifying at the receiver.
Because the free plugin has no way to tell which cached responses a change touches, so any post, term or comment change flushes everything. API Gateway Pro answers the bfag_cache_purge_tags filter with the tags each change touches (post:42, type:product, term:7, tax:category, all), so a rule tagged type:product survives a blog post edit. A rule with no tags is purged on every content change even with Pro; add tags to narrow purging to those tags.
No. A request with a WordPress login cookie, an Authorization header (Application Passwords, bearer tokens), an X-WP-Nonce or an X-BF-API-Key is never served from or stored in the cache, because such a response may contain data nobody else should see. Only anonymous public reads are cached.
Up to 500 cache rules, 500 rate-limit rules and 500 webhooks — the same with or without API Gateway Pro. The ceiling keeps the admin lists and the rule matching on every request quick; a developer can lower it, or raise it to at most 1,000, with the bfag_cache_rule_limit, bfag_rate_limit_rule_limit and bfag_webhook_limit filters. When every one is in use the add form gives way to a line saying so: edit or delete one to add another. Rate limiting counts by IP address; Pro adds per-user and per-API-key counting.
Each refused field has its own notice: URL refused… for the URL, Webhook not saved: the label must be 1–200 characters for the label, Webhook not saved: choose an event from the list for the event, and Webhook not saved: check the extra headers (one Name: value per line) and the secret (255 characters at most) for the rest. Your entries are kept in the form.
The URL must start with https:// and must pass WordPress's own wp_http_validate_url() check, which refuses loopback and private addresses such as localhost, 127.0.0.1 or 10.x.x.x. For local development a developer can allow http:// with the bfag_webhook_allow_http filter. The event must be one offered in the dropdown — a WooCommerce event disappears from the list when WooCommerce is deactivated.
A generated secret is shown exactly once, on the Webhooks tab right after you save, with a Copy button; after that the stored secret cannot be read back from the admin page. If you missed it, edit the webhook and either type your own secret into the field, or tick Generate a new secret and save — the new one is shown once in the same way. Either way, update the receiver: deliveries fail there until it has the new secret.
The hit-log prune, the delivery-log prune and the dashboard figures run on WP-Cron. The first 20 webhook deliveries of a request are sent at the end of that request; the rest are queued and sent by bfag_cron_flush_pending, a single event scheduled on demand. If DISABLE_WP_CRON is set the plugin shows a notice on its own screen; make sure a system cron runs wp-cron.php, then tick Hide the WP-Cron notice. There are no WP-CLI commands; wp cron event run bfag_cron_prune_hits runs a job on demand.
Yes. While WooCommerce is active four more events are offered: order created, order status changed, order completed and product updated, each carrying the order or product fields (id, status, currency, total, customer id, billing email; id, name, SKU, status, price, type). WooCommerce's own REST routes under wc/v3/… can be cached and rate-limited like any other, subject to the same rule that authenticated requests are never cached.
Network activation provisions every site — tables, the seeded rules, the capability and the cron jobs — and a site added later is provisioned when it is created. Each site keeps its own rules, webhooks and settings. Uninstalling cleans up on every site of the network.
bfag_rate_limit_exempt.init. With WooCommerce (or another plugin that translates its cron schedule names) active, WordPress logged "Translation loading for the woocommerce domain was triggered too early". The jobs are now booked at init, on that same page load.docs/ApiGatewayFeaturesGuide.pdf.X-BF-Cache: HIT / MISS / BYPASS, one route-glob rule, object-cache or transient storage (64 KB / one-hour cap on transients), generation-based purging on post, term and comment changes, Purge all, and POST /bfag/v1/cache/purge.429, Retry-After and X-BF-RateLimit-* headers; one rule seeded at 300 per 60 s; editors exempt by default in a browser session (never API-key traffic); trusted-proxy IP resolution from one chosen header; refused requests served from a marker with no database work.X-BF-Signature over timestamp.body, delivery after the response (twenty at most, fifteen seconds at most, the rest by WP-Cron), a delivery log with Send test and Retry on failed outgoing deliveries, payload truncation and retention pruning.GET /bfag/v1/status for monitors, the bfag_manage_gateway capability, multisite provisioning.bfag_* actions and filters as the add-on contract.