Skip to content

Support JSON error response bodies#13415

Open
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:header-rewrite-json-bodies
Open

Support JSON error response bodies#13415
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:header-rewrite-json-bodies

Conversation

@bneradt

@bneradt bneradt commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

ATS cannot reliably emit JSON error responses through header rewrite: literal bodies cannot select a MIME type, HRW4U interprets JSON braces as interpolation, fetched bodies lose their Content-Type, and conditional local files are unavailable. Body factory error pages are also hardcoded to HTML.

Changes

  • Add optional Content-Type arguments to set-body and set-body-from.
  • Preserve the fetched response Content-Type unless a rule overrides it.
  • Add set-body-from-file, loaded once at rule-configuration time.
  • Add HRW4U literal JSON braces and the MIME-aware body forms.
  • Add configurable body-factory Content-Type metadata.
  • Document and test literal, fetched, file-backed, and body-factory bodies.

The asynchronous URL form remains READ_RESPONSE-only because remap callbacks cannot suspend for an internal fetch. REMAP errors are handled by the literal or file-backed forms without origin or cache lookup.

This includes the body-factory work from #12947 and preserves Bryan Call's original commits.

Related: #10893
Fixes: #13393
Fixes: #11480

Copilot AI review requested due to automatic review settings July 21, 2026 18:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bneradt bneradt self-assigned this Jul 21, 2026
@bneradt bneradt added this to the 11.0.0 milestone Jul 21, 2026
Copilot AI review requested due to automatic review settings July 21, 2026 20:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 21, 2026 20:16
@bneradt
bneradt force-pushed the header-rewrite-json-bodies branch from c2e2428 to 857086d Compare July 21, 2026 20:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

ATS cannot reliably emit JSON error responses through header rewrite:
literal bodies cannot select a MIME type, HRW4U treats JSON braces as
interpolation, fetched bodies lose their Content-Type, and conditional
local files are unavailable. Body factory error pages are also
hardcoded to HTML.

This adds optional Content-Type arguments to set-body and
set-body-from, preserves fetched response types, adds configuration-time
local file bodies, and teaches HRW4U literal JSON braces and MIME-aware
forms. It also adds body-factory Content-Type metadata and clears stale
MIME state for empty fabricated bodies.

Network set-body-from remains READ_RESPONSE-only because remap hooks
cannot suspend for its asynchronous fetch. This covers remap-time errors
with literal or file-backed bodies instead.

This incorporates Bryan Call's body-factory work from apache#12947.

Related: apache#10893
Fixes: apache#13393
Fixes: apache#11480
Co-authored-by: Bryan Call <bcall@apache.org>
@bneradt
bneradt force-pushed the header-rewrite-json-bodies branch from 857086d to a791484 Compare July 21, 2026 21:15
Copilot AI review requested due to automatic review settings July 21, 2026 21:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't find a way to serve JSON errors header_rewrite set-body feature only supports the most basic of response bodies

2 participants