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.

https requests failing when using a proxy

See original GitHub issue

I’m using the dynamics-web-api to make https requests via the squid proxy. The https request works fine when doing a curl command. But I get the following error “The requested URL could not be retrieved”.

When the curl command is run in squid I can see: 225 172.17.0.1 TCP_TUNNEL/200 5122 CONNECT example.com:443 - HIER_DIRECT/40.110.1111.111 - Whereas when using the dynamics API I get 0 172.17.0.1 TAG_NONE/501 5910 GET example.com - HIER_NONE/- text/html

I presume it’s down to this https://github.com/AleksandrRogov/DynamicsWebApi/blob/v1.7.1/lib/requests/http.js#L51. But just wanted to confirm. It probably needs to make a CONNECT request first then perform the request. https://stackoverflow.com/questions/34078995/how-can-i-use-an-https-proxy-with-node-js-https-request-client

Would the ideal solution be to use something like axios to perform the requests?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AleksandrRogovcommented, Feb 23, 2021

@nabeelamir-defra I am not going to use axios, because those packages do not require it and I don’t want to introduce another dependecy (I’ve already added 2). Hope it will work for you fine. The patch will be ready soon.

0reactions
nabeelamir-defracommented, Feb 23, 2021

Sorry for getting back to you so late. Did you use the https-proxy-agent with the existing solution or with axios?

Using axios seem to be more robust and require less code. The axios code looks ok (I haven’t tested it), but you don’t need to configure the proxy.

if (process.env[`${protocol}_proxy`]) {
		headers.host = parsedUrl.host;

		var proxyUrl = url.parse(process.env.http_proxy);
		axiosConfig.proxy = {
			protocol: proxyUrl.protocol,
			host: proxyUrl.hostname,
			port: proxyUrl.port
		}
	}

axios respects the http_proxy, https_proxy and no_proxy environment variables already. From the docs:

// You can also define your proxy using the conventional `http_proxy` and
  // `https_proxy` environment variables. If you are using environment variables
  // for your proxy configuration, you can also define a `no_proxy` environment
  // variable as a comma-separated list of domains that should not be proxied.

And the code https://github.com/axios/axios/blob/master/lib/adapters/http.js#L125

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request to HTTPS with HTTP proxy fails #925 - axios ... - GitHub
Had a similar issue recently, my solution was to use an HTTPS-over-HTTP tunnel, specify port 443 explicitly in the URL and disable automatic ......
Read more >
Problems using a HTTPS proxy with Python requests
I have problems using a NordVPN HTTPS proxy correctly with the requests package. This is what I tried (not documented by NordVPN but...
Read more >
HTTPS requests with SoapUI and the HTTP Proxy Agent fail
After configuring SoapUI to use the HTTPS Proxy Agent on port 3129 you are unable to access HTTP sites. No replies are received...
Read more >
HTTP and HTTPS Request and Proxy Settings - Sonatype Help
Many organizations use proxy servers for any outbound HTTP network traffic. ... attempts to make when requests fail can be configured with these...
Read more >
How to use proxies with Python Requests Proxy Module - Zyte
Because sometimes the proxy that you are trying to use is just simply banned. In this case, there's not much you can do...
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