Rewriting Hostname of target url, via go plugin

I want to rewrite the hostname of target url, based off of an issuer(iss) url in the bearer token (JWT).

I see plenty of examples of rewriting the path (e.g., /api/v1/resource/foobar). For the stock tyk proxy, I would be looking to swap out http://httpbin.org/ with something like https://foobar1.mysite.com/. Foobar1 being the site that issued the JWT.

I have tried various options in Go lang, including things such as:

apiDef.Proxy.TargetURL = *Issuer

r.Header.Set(“Host”, Issuer)

Hello @james.mclauchlin! Welcome to the community :tada:

Have you checked our custom plugin examples? We have a sample there that you would find useful

Yes, I have looked through the custom plugin examples. In fact, I borrowed some code from it for the setUpstream function. However, I can’t seem to override the target url.

FYI, even though I don’t need it, the NewHostListFromList is not a valid “call” anymore, at least with 5.2.5.

Basically, what I am looking for is the “call” that will point to that exact Tyk parameter to replace the configured target url (aka, backend call that is being proxied). Hostname, specifically, is what I want to replace, leaving the rest of path is fine.

FYI, even though I don’t need it, the NewHostListFromList is not a valid “call” anymore, at least with 5.2.5.

We will check this behaviour and get back to you.

Basically, what I am looking for is the “call” that will point to that exact Tyk parameter to replace the configured target url (aka, backend call that is being proxied). Hostname, specifically, is what I want to replace, leaving the rest of path is fine.

From the source, it should be the Proxy.TargetURL but I don’t think it’ll work. You could try and let us know

I do want to ask, is there a particular reason you are using a GoPlugin? You could use context variables with an optional modify headers middleware depending on the advanced URL Rewrite chosen to achieve the same thing.

FYI, even though I don’t need it, the NewHostListFromList is not a valid “call” anymore, at least with 5.2.5.

We tried on v5.2.5 and it works. Here is a link to the golang plugin we tried How do I change the target_url for my proxy in a Custom Go Plugin? - #2 by Firas