question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use proxy via REST helper

See original GitHub issue

I would like to add a proxy parameter on REST helper, like on webdriver Helper

I don’t know how I have to do

I have error

502 bad gateway

"helpers": {
    "REST": {
      "endpoint",
      "defaultHeaders": {
        "X-APIKey": "test",
        "Authorization": 
        "Accept": "application/json"
      }
    }
  }
        "WebDriver": {
            "url": "http://{{url}}:86/oskar-ng/",
            "browser": "chrome",
            "restart": false,
            "windowSize": "300x800",
            "host": "localhost",
            "port": 4444,
            "desiredCapabilities": {
                "browserName": "chrome",
                "chromeOptions": {
                  "args": [ "--user-agent=Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36"]
                },
                **"proxy": {
                  "proxyType": 
                  "proxyAutoconfigUrl": 
                }**
            }
        }
    }

I did this for webdriver but I can’t do it for REST helper

My question: Is there a way to do this ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
commonquailcommented, Sep 28, 2020

I was able to confirm that

By analogy try to pass proxy object to onRequest

“works” – that is, as suggested, the proxy value is passed correctly to axios – but I simply could not get axios to communicate with our proxy the way our proxy expects. This may have been an HTTPS-over-HTTP obstacle (and it would not surprise me that the limitation is in the proxy rather than in axios, but either way).

However, I was able to disable axios’ own proxy configuration and override its HTTP(S) agent with https-proxy-agent@5.0.0 and get that working:

const HttpsProxyAgent = require("https-proxy-agent");

...

  REST: {
    endpoint: "https://reqres.in", // NB: no trailing slash
    onRequest: (request) => {
        if (process.env.https_proxy) {
            // Forcefully disable axios' own proxy config, because it just
            // doesn't work right in our situation.
            request.proxy = false;
            request.httpsAgent = new HttpsProxyAgent(process.env.https_proxy);
        }
        if (process.env.http_proxy) {
            request.proxy = false;
            request.httpAgent = new HttpsProxyAgent(process.env.http_proxy);
        }
    }

I got this solution from an axios ticket.

0reactions
AdamOakmancommented, Mar 28, 2019

Maybe this will help, in my case I needed to disable proxy at all:

        REST: {
            endpoint: getEnv('grafUrl'),
            onRequest: (request) => {
                request.proxy = false;
            }
        }

By analogy try to pass proxy object to onRequest

proxy: {
    host: '127.0.0.1',
    port: 9000,
    auth: {
      username: 'mikeymike',
      password: 'rapunz3l'
    }
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using a Proxy to Call a REST Service | Mendix Documentation
There are two parameters that specify which proxy server to use when making REST calls: http.proxyHost and http.proxyPort . Some proxies require ...
Read more >
Using a Proxy Server to Authorize the REST API
This section explains how the REST API handles proxy server issues, then shows how to set up an Apache proxy server for the...
Read more >
Proxies With RestTemplate | Baeldung
Sending a request to a proxy using RestTemplate is pretty simple. All we need to do is to call the setProxy(java.net.
Read more >
Consuming REST API through http-proxy? - BMC Communities
I want to consume an external REST API in a filter with the set-fields action and REST data source, but need to do...
Read more >
How to build a REST client with JavaScript proxies
Why should you use a proxy? · To have full control over data · To ensure the correct behavior of objects or functions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found