Skip to content

Conversation

@haacked
Copy link
Contributor

@haacked haacked commented Dec 3, 2025

Add HTTP ETag caching for feature flag definitions to reduce bandwidth when polling for flag updates. When flags haven't changed, the server returns 304 Not Modified and cached flags are preserved.

Based on the work we did for PostHog/posthog-js#2678

Add HTTP ETag caching for feature flag definitions to reduce bandwidth when polling for flag updates. When flags haven't changed, the server returns 304 Not Modified and cached flags are preserved.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements HTTP ETag-based caching for feature flag definitions in the PostHog PHP library, reducing bandwidth consumption during flag polling. When flags haven't changed, the server returns a 304 Not Modified response, allowing the client to reuse cached flag data instead of re-transmitting the full payload.

Key Changes

  • Added ETag extraction and storage from HTTP responses with If-None-Match header support for conditional requests
  • Enhanced HttpResponse class to include ETag metadata and 304 status detection
  • Updated MockedHttpClient test infrastructure to support ETag scenarios and response queuing

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/HttpResponse.php Added ETag property, getter method, and isNotModified() helper for 304 detection
lib/HttpClient.php Implemented ETag extraction from response headers, 304 status handling, and token masking utility
lib/Client.php Added ETag caching state, If-None-Match header injection, and 304 response handling in loadFlags()
lib/PostHog.php Added getClient() method to expose Client instance for accessing ETag functionality
test/EtagSupportTest.php Comprehensive test suite covering ETag storage, If-None-Match headers, 304 handling, and edge cases
test/HttpClientTest.php New tests for token masking functionality in URLs
test/MockedHttpClient.php Enhanced mock to support ETag responses and sequential response queuing for testing
test/PostHogTest.php Updated test expectations to include includeEtag request option
test/FeatureFlagTest.php Updated test expectations to include includeEtag request option
test/FeatureFlagLocalEvaluationTest.php Updated test expectations to include includeEtag request option
example.php Added interactive ETag polling example demonstrating bandwidth optimization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@haacked haacked marked this pull request as ready for review December 3, 2025 23:54
@haacked haacked requested a review from a team December 3, 2025 23:54
@posthog-project-board-bot posthog-project-board-bot bot moved this to In Review in Feature Flags Dec 3, 2025
@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Dec 4, 2025
@haacked haacked merged commit 764196d into master Dec 4, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants