F5Networks / f5-appsvcs-extension

F5 BIG-IP Application Services 3 Extension
Apache License 2.0
169 stars 54 forks source link

Add custom request headers when fetching external URL resources #870

Open megamattzilla opened 2 months ago

megamattzilla commented 2 months ago

When AS3 fetches remote URL resources, customers need a way to specify custom HTTP request headers on the GET request.

Describe the solution you'd like:

When specifying any external URL reference, add schema so that custom HTTP request header name and values can be specified.

For example, in order for AS3 to fetch resources from githubs REST API endpoint api.github.com, the request header "Accept: application/vnd.github.raw+json" must be specified.

Example AS3 Schema:

{
    "exampleWAF": {
        "class": "WAF_Policy",
        "url": {
            "url": "https://api.github.com/repos/user/coolrepo/waf_policy.xml",
            "extra-headers": [
                {
                    "Accept": "application/vnd.github.raw+json"
                }
            ]
        }
    }
}

Ideally:

Currently, there is no easy way to add this to the GET request when AS3 fetches the resource. I found that I could modify /var/config/rest/iapps/f5-appsvcs/lib/util/util.js file on Big-IP to hard-code extra request headers, but this is global, messy, and unsupported.

((Fun fact)) the modification is adding these 3 lines and restarting restnoded:

            if (typeof opts.headers['Accept'] !== 'string') {
                opts.headers['Accept'] = 'application/vnd.github.raw+json';
            }

After that, i am able to fetch files from github REST API.