f5-appsvcs-extension icon indicating copy to clipboard operation
f5-appsvcs-extension copied to clipboard

Add custom request headers when fetching external URL resources

Open megamattzilla opened this issue 5 months ago • 0 comments

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:

  • n-number HTTP request header name/values using an item array
  • specified per URL reference if some URLs need special headers and others don't

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.

megamattzilla avatar Sep 12 '24 15:09 megamattzilla