Reverse URL Transformations in Gloo, Kong, etc

376 views Asked by At

I've been googling and googling and I'm still trying to understand one aspect of API gateways like Gloo or Kong. I understand that you can configure them so that externally facing URLs get "connected" to internal servers behind the scenes with potentially quite different URLs. That part seems like a straightforward mapping exercise.

But what I don't understand is what you do if one of these services returns a URL (to itself or even other services) in its response. I can't really see many examples of how you would handle this. Taking Gloo as an example, the VirtualService instance will define the "forward" routing (taking publicly facing URLs and requests and rewriting them to forward to internal services). The services on the "inside" don't know what this routing looks like, so they can't predict what the public facing URLs would be. So I would have assumed they would return (e.g., JSON) responses with links in them using the (only) routes they know and that the API gateway would then take the responses and rewrite any links in them.

But I cannot find any documentation on this? In particular, what I'm interested in is having one service return links that resolve to other services and ensuring those rewrites are done correctly too. As far as I can see, the information required is all stored in the VirtualService and, therefore, nobody but the Gloo proxy could really do this rewriting and I don't see any evidence it does.

Am I missing something?!?

Thanks

1

There are 1 answers

0
Rinor On

The Gloo Edge supports transforming the response within the proxy and it can be specified within the VirtualService. The documentation shows the example below that transforms the ":status" of a response:

apiVersion: gateway.solo.io/v1
kind: VirtualService
metadata:
  name: update-response-code
  namespace: gloo-system
spec:
  virtualHost:
    domains:
    - '*'
    routes:
    - matchers:
       - prefix: /
      routeAction:
        single:
          upstream:
            name: postman-echo
            namespace: gloo-system
      options:
        autoHostRewrite: true
    options:
      transformations:
        responseTransformation:
          transformationTemplate:
            headers:
              # We set the response status via the :status pseudo-header based on the response code
              ":status":
                text: '{% if default(data.error.message, "") != "" %}400{% else %}{{ header(":status") }}{% endif %}'

You can find all the transformation options at the API documentation which should support your intent of changing the host and path headers (i.e. URL).