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

Add set-custom-body config item to header_rewrite #11472

Open jasmine-nahrain opened 1 week ago

jasmine-nahrain commented 1 week ago

Adding config item set-custom-body to header rewrite. The config takes in a url. When triggered, there will be a secondary call the the specified endpoint to get a response body from. What the client will see is the response body from the second call. The second call goes through as an internal ATS request and goes gets remapped. The status of the original transaction will remain in all error status code cases. OK status codes will appear as a 500 error code due to the nature of TSHttpTxnErrorBodySet.

e.g. set_custom_body.conf

cond %{READ_RESPONSE_HDR_HOOK} [AND]
cond %{STATUS} = 404
set-custom-body https://example.com/404

remap.config

map /home http://example.com/home @plugin=header_rewrite.so @pparam=set_custom_body.conf
map http://example.com/404 http://example.com/404

With the above configs, when /home returns a 404 status code, a second call will be made to /404 through ATS internal request The response that is sent to the client is

JosiahWI commented 6 days ago

The AuTest prefetch_overflow failed.

   Run: 2-tr: Failed
     Starting TestRun 2-tr : No Issues found - Passed
        Reason: Started!
     Process: Default: Failed
       Test : Checking that ReturnCode == 0 - Passed
          Reason: Returned Value: 0 == 0
       file /tmp/sandbox/prefetch_overflow/_output/2-tr-Default/stream.stdout.txt : Checking that /tmp/sandbox/prefetch_overflow/_output/2-tr-Default/stream.stdout.txt matches prefetch_overflow.gold - Failed
          Reason: File differences
           Gold File : /home/jenkins/workspace/Github_Builds/autest/src/tests/gold_tests/pluginTest/prefetch/prefetch_overflow.gold
           Data File : /tmp/sandbox/prefetch_overflow/_output/2-tr-Default/stream.stdout.txt
             GET http://domain.in/texts/demo-3594967639391.txt HTTP/1.1
           - GET http://domain.in/texts/demo-3594967639392.txt HTTP/1.1
           - GET http://domain.in/texts/demo-3594967639393.txt HTTP/1.1
           - GET http://domain.in/texts/demo-3594967639394.txt HTTP/1.1

The AuTest prefetch_bignum failed:

   Run: 2-tr: Failed
     Starting TestRun 2-tr : No Issues found - Passed
        Reason: Started!
     Process: Default: Failed
       Test : Checking that ReturnCode == 0 - Passed
          Reason: Returned Value: 0 == 0
       file /tmp/sandbox/prefetch_bignum/_output/2-tr-Default/stream.stdout.txt : Checking that /tmp/sandbox/prefetch_bignum/_output/2-tr-Default/stream.stdout.txt matches prefetch_bignum.gold - Failed
          Reason: File differences
           Gold File : /home/jenkins/workspace/Github_Builds/autest/src/tests/gold_tests/pluginTest/prefetch/prefetch_bignum.gold
           Data File : /tmp/sandbox/prefetch_bignum/_output/2-tr-Default/stream.stdout.txt
             GET http://domain.in/texts/demo-3842948374928374982374982374.txt HTTP/1.1
           - GET http://domain.in/texts/demo-3842948374928374982374982375.txt HTTP/1.1
           - GET http://domain.in/texts/demo-3842948374928374982374982376.txt HTTP/1.1
           - GET http://domain.in/texts/demo-3842948374928374982374982377.txt HTTP/1.1
JosiahWI commented 5 days ago

The AuTest transaction_data_sink failed.

     file /tmp/sandbox/transaction_data_sink/ts/log/traffic.out : The expected HTTP/2 response body was dumped. - Failed
        Reason: Contents of /tmp/sandbox/transaction_data_sink/ts/log/traffic.out did not contains expression: ""http2_response_body_dumped""