Layer7 API Management

 View Only
  • 1.  Changing HTTP Status

    Posted Apr 27, 2017 09:39 AM

    Hello,

     

    I was wondering if there is a way to change the HTTP Status of the response returned by the Route via HTTP assertion. Just like how you can use the Manage Transport Properties/Headers to add or modify existing headers. I would like to keep everything about the response as is but only change the status code.

     

    Thanks.



  • 2.  Re: Changing HTTP Status
    Best Answer

    Posted Apr 27, 2017 10:35 AM

    Hi Guzman,

    You can test using the Return Template Response to Requestor assertion that allows you to modify the Response status. To get the body of the response in a context variable:

    1. Modify the route:
    2. Include the context variable in Template response ${httpResponse1.mainpart}


  • 3.  Re: Changing HTTP Status

    Posted Apr 27, 2017 11:00 AM

    Hi Mohindra,

     

    I did consider this but I couldn't get the existing headers preserved with this. As you can see this only sets the Content Type header.

     

    Thanks for the reply.



  • 4.  Re: Changing HTTP Status

    Posted Apr 28, 2017 08:05 AM

    Hi Guzman,

    That's right, the headers will not be passed. 
    You can store the ${response.http.allheardervalues} to a multivalued context variable.
    Use the For Each Item Assertion to parse the array with the Manage Transport Properties/Headers Assertion to send the headers.

    ${<target>.http.allheadervalues} 

    Returns all HTTP headers and values in an array, in the format "<name>:<value>".



  • 5.  Re: Changing HTTP Status

    Posted Apr 28, 2017 02:15 PM

    Thanks Mohindra. That is helpful.



  • 6.  Re: Changing HTTP Status

    Posted May 22, 2018 10:17 PM

    Are you able to modify the response status code?

    I have a similar requirement to send status code with status-line/message (like "invalid field").

     

    Please confirm.