Change response status
Update the response status based on headers being present in a response.
Before you begin
Follow the Get started guide to install Gloo Gateway.
Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
Change the response status
Create a GlooTrafficPolicy resource with your transformation rules. In this example, you change the value of the
:statuspseudo response header to 401 if the response headerfoo:baris present. If thefoo:barresponse header is not present, you return a 403 HTTP response code.Send a request to the httpbin app and include the
foo:barquery parameter. This query parameter automatically gets added as a response header and therefore triggers the transformation rule that you set up. Verify that you get back a 401 HTTP response code.Example output:
< HTTP/1.1 401 Unauthorized HTTP/1.1 401 Unauthorized < access-control-allow-credentials: true access-control-allow-credentials: true < access-control-allow-origin: * access-control-allow-origin: * < content-type: application/json; encoding=utf-8 content-type: application/json; encoding=utf-8 < foo: bar foo: bar < content-length: 29 content-length: 29 < x-envoy-upstream-service-time: 4 x-envoy-upstream-service-time: 4 < server: envoy server: envoy < { "foo": [ "bar" ] }Send another request to the httpbin app. This time, you include the
foo:bazquery parameter. Verify that you get back a 403 HTTP response code.Example output:
< HTTP/1.1 403 Forbidden HTTP/1.1 403 Forbidden < access-control-allow-credentials: true access-control-allow-credentials: true < access-control-allow-origin: * access-control-allow-origin: * < content-type: application/json; encoding=utf-8 content-type: application/json; encoding=utf-8 < foo: bar foo: bar < content-length: 29 content-length: 29 < x-envoy-upstream-service-time: 4 x-envoy-upstream-service-time: 4 < server: envoy server: envoy < { "foo": [ "bar2" ] }
Cleanup
You can remove the resources that you created in this guide.
kubectl delete GlooTrafficPolicy transformation -n httpbin