Skip to content

Expand response post-processing middleware guide#469

Open
samdark wants to merge 1 commit into
masterfrom
docs-response-post-processing
Open

Expand response post-processing middleware guide#469
samdark wants to merge 1 commit into
masterfrom
docs-response-post-processing

Conversation

@samdark
Copy link
Copy Markdown
Member

@samdark samdark commented May 30, 2026

Summary

  • expand the middleware guide's response capture section
  • show verified middleware examples for security headers and response body transformation
  • call out PSR-7 immutability and stale Content-Length/ETag style headers after body changes

Verification

  • Used a fresh yiisoft/app template created with composer create-project yiisoft/app /tmp/yii-docs-upload-app --no-interaction
  • Added the example middleware classes and a verification script to the template app
  • Ran php -l src/Web/Middleware/SecurityHeadersMiddleware.php && php -l src/Web/Middleware/TextResponseTransformMiddleware.php && php -l verify-response-post-processing.php
  • Ran php verify-response-post-processing.php; verified security headers are added, body is transformed, and stale Content-Length is removed
  • Ran vendor/bin/phpstan analyse src/Web/Middleware/SecurityHeadersMiddleware.php src/Web/Middleware/TextResponseTransformMiddleware.php verify-response-post-processing.php --level=max --no-progress
  • Ran vendor/bin/psalm --no-cache --output-format=console src/Web/Middleware/SecurityHeadersMiddleware.php src/Web/Middleware/TextResponseTransformMiddleware.php verify-response-post-processing.php
  • Ran npm run build

npx markdown-link-check src/guide/structure/middleware.md still fails on the page's pre-existing absolute image links: /images/guide/middleware.svg and /images/guide/middleware_alternative.svg.

Copilot AI review requested due to automatic review settings May 30, 2026 10:42
Copy link
Copy Markdown
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

The PR expands the "Capturing response to manipulate it" section in the middleware guide with two concrete, verified examples (security headers, body transformation), and adds notes on PSR-7 immutability, stale headers after body changes, and large-response handling.

Changes:

  • Rewords the section intro and fixes the "extra handing" typo.
  • Adds a SecurityHeadersMiddleware example and notes on PSR-7 immutability.
  • Adds a TextResponseTransformMiddleware example using StreamFactoryInterface, with guidance on removing stale Content-Length/ETag headers and avoiding loading large bodies in memory.

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.

2 participants