Jan 18, 2023 — respondWith support for the onOriginResponse event handler
almost 3 years ago
You can now use onOriginResponse and onOriginRequest to dynamically build a response from your JavaScript code using the respondWith method.
If you include both the construct-response in the metadata and respondWith in your JavaScript code, the last one that runs will win.
Use the onOriginResponse event handler to :
- Construct a response based on the results of a conditional match of the response received from an origin server.
- Construct a custom error or redirect page if the origin responds with an error or redirect status code.
- Provide multiple choice, status code 300, origin response handling.
- If the origin replies with a list of URLs pointing to domains in various physical locations, you can apply a rule that:
- Uses the best geolocation match.
- Constructs a response using
responseWiththat includes only the relevant response.
- Handle 5xx errors from the origin, using a
respondWithredirect page that provides details about the original query instead of transferring the 5xx status code. - Handle any type of origin response authentication procedure.
Use the onOriginRequest event handler to:
- Test the outcome of a client-request metadata stage execution.
- Use the test results to make decisions based on variables set up during that stage.
- Validate the completion of a sub-request invoked using the
onClientRequestevent handler. If the attempt fails and information is missing from the request the results should be sent to Origin, and the flow terminated usingrespondWith.
