CA API Management: How to handle URL Hash Fragments

Document ID : KB000016682
Last Modified Date : 14/02/2018
Show Technical Document Details
Question:

How can the Gateway handle URL Hash Fragments? In the below example I would like to retrieve the value of product.

 

i.e: https://ssg.com:8443/service#product=gateway

Answer:

The hash fragments of a URL are not sent to the server (Gateway) and will need to be handled via the user agent using a client side language such as JavaScript.

For this purpose you can use a 'Return Template Response to Requestor' assertion.

 

You can use JavaScript to convert the hash fragment to a query parameter (which the Gateway can see) and redirect the request back to the Gateway.

This can be accomplished using the below code within a return template response. It will retrieve the first hash value and send the browser back to the same service appending the hash as ?product=Gateway. This can now be utilized with the ${request.http.parameter.product} built-in context variable and can be used within policy to manipulate the value.

 

<script type="text/javascript">

if (window.location.hash.length != 0) {

var queryString = location.hash.substring(1);

window.location = "${request.url.protocol}://${request.url.host}:${request.url.port}${request.url.path}?" + queryString

}

 

</script>