apache / trafficserver

Apache Traffic Serverâ„¢ is a fast, scalable and extensible HTTP/1.1 and HTTP/2 compliant caching proxy server.
https://trafficserver.apache.org/
Apache License 2.0
1.74k stars 781 forks source link

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

Open djcarlin opened 4 days ago

djcarlin commented 4 days ago

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 commented 4 days ago

Maybe related to #11472