Layer7 API Management

 View Only

 Return response immediately with headers

Jump to Best Answer
Ozgur Anil Demir's profile image
Ozgur Anil Demir posted Dec 06, 2022 04:04 AM
Hello,

I have an issue about the return response immediately with headers. 

We need to return response message with headers and stop process.
But "Return Template Response to Requestor" assertion does not send headers when the "Send Response Immediately" box selected.

I saw that is not possible in 2017 from the discussion below.
Layer7 API Management

Is it fixed or is there any other way to overcome this issue?

Regards

Özgür Anıl Demir
Barry Stern's profile image
Broadcom Employee Barry Stern Best Answer

Hello,

you do not need to use "Send response Immediately" for this. your policy needs to be enhanced to handle error handling  so if your validation logic fails you fails the policy and return a error to the requestor instead of routing to the backend

there are several approaches to this but here is a simple sample showing error handling as well as adding a custom header for the response for a validation error

Barry Stern's profile image
Broadcom Employee Barry Stern
It is usually not advisable to use the "Send Response Immediately" option as it returns responses to client but policy continues processing and if there are issues after the response is sent the requestor will never know about them.  What is the use case that you want to use the "Send Response Immediately" option?
Jay MacDonald's profile image
Broadcom Employee Jay MacDonald
I'll second Barry's response. The send response immediately is not recommended except in very specific cases. As I recall the adding of headers to the response happens much later in the processing. What is the use case where you feel the need to send the response immediately?
Ozgur Anil Demir's profile image
Ozgur Anil Demir
Hello Barry andJay,

I can not reply your comments somehow, so I'm answering my own. 

We have many validations on API Gateway.

When the validation fails API Gateway does not route request to the backend services and send validation message to the requestor.
If validation does not fails API Gateway routes the request to the backend services, then Gateway add some header backend's response and send it back to the requestor at the end of the policy.

When the validation fails we need to stop proccessing and send back the validation message to the requestor.
At this point, due to banking regulations, we need to add some headers to the validation messages.

So is there any other way to stop proccessing and send our validation messages to the requestor with headers for every single validation?

Thanks,

Özgür Anıl Demir 
Barry Stern's profile image
Broadcom Employee Barry Stern

Hello,

You can accomplish this using Error Handling in your policy and not require use of send response immediately.

//Here is a simple sample of a policy that includes some error handling and I also added a repose header as you need when returning a error response.