trafficserver icon indicating copy to clipboard operation
trafficserver copied to clipboard

header_rewrite set-body feature only supports the most basic of response bodies

Open djcarlin opened this issue 1 year ago • 2 comments

set-body in ATS 9.2 doesn't support whitespace or newlines.

I was trying to use set-body to send a two line JSON response and couldn't get it to work. Trying to add "\n" or spaces for human readable formatting just resulted in a truncated set-body. The set-body setting also doesn't include a newline by default at the end of the body. If you do set-body "OK" there is no newline sent to the client.

can set-body reference a file on the local filesystem and serve that as a response body? Similar to what statichit plugin does, but with header_rewrite the operation can be performed when certain conditions are met.

Additionally, set-body seems to force Content-Type: text/html - I'd like to be able to specify something else like "application/json". I tried using:

cond %{SEND_RESPONSE_HDR_HOOK}
rm-header Content-Type
add-header Content-Type "application/json"

but its still overridden with text/html when I use set-body option.

djcarlin avatar Jun 26 '24 15:06 djcarlin

Maybe related to #11472

djcarlin avatar Jun 26 '24 15:06 djcarlin

This issue has been automatically marked as stale because it has not had recent activity. Marking it stale to flag it for further consideration by the community.

github-actions[bot] avatar Jun 27 '25 02:06 github-actions[bot]