Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy servers #56

Open
Quafadas opened this issue Mar 18, 2020 · 5 comments
Open

Proxy servers #56

Quafadas opened this issue Mar 18, 2020 · 5 comments

Comments

@Quafadas
Copy link

Quafadas commented Mar 18, 2020

Does this library work behind a corporate proxy.
I think the keywords in python are somehow verify="cert/location",proxies="proxy"... couldn't see anything in the docs so assuming it's not currently implemented. Will try and look but it's probably beyond my skills :-(.

Or is this solved by the open pull request? (he asks hopefully)

@anicolaspp
Copy link

@Quafadas I had the same issue and I couldn't find anything on the library. However, you can set your JVM to go through the proxy.

We used something like this:

case class Proxy(url: String, port: Int, user: Option[String] = None, pass: Option[String] = None, scheme: String = "http") {
  override def toString: String = s"PROXY (URL: $url; PORT: $port; SCHEME: $scheme)"
}

object Proxies extends LoggingSupport {
  def autoSetup(config: ConfigurationReader) = {
    val proxies = config.PROXIES

    if (proxies.nonEmpty) {
      logger.info("Setting up proxies.")
    } else {
      logger.info("No proxies found.")
    }

    proxies.foreach { proxy =>
      logger.debug(proxy.toString)

      System.setProperty(s"${proxy.scheme}.proxyHost", proxy.url)
      System.setProperty(s"${proxy.scheme}.proxyPort", proxy.port.toString)

      proxy.user.foreach(user => System.setProperty(s"${proxy.scheme}.proxyUser", user))
      proxy.pass.foreach(pass => System.setProperty(s"${proxy.scheme}.proxyPassword", pass))
    }

    config.PROXY_BYPASS.foreach(exp => System.setProperty("https.nonProxyHosts", exp))
    config.PROXY_BYPASS.foreach(exp => System.setProperty("http.nonProxyHosts", exp))
  }
}

Notice that this implementation is based on the Oracle documentation that can be found here.

https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html

@Quafadas
Copy link
Author

Okay, thanks for the above. I'll let you know if I get any mileage.
I had a dig into the code and there does appears to be support for proxies=(String, Int)... in the requests arguments, although it's not documented.

But I think our proxy is doing something weird. I can send a request to the service which gives me back a token, but I think the proxy is stripping the Authorization header of the subsequent requests. I can only ever get back unauthorised... but I can test in Postman etc, that the Authorization header I'm sending is correct... and Postman itself works.

I'm lost :-( ... but I'm not sure the problems are in this library... I have a hint that it may be to do with getting SSL correctly setup with client certs... but mostly... I'm just lost.

@Quafadas
Copy link
Author

TO clarify this, I can never get beyond this stage;

play.api.UnexpectedException: Unexpected exception[IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"] at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:347) at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:267) at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:448) at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:446) at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:417) at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:41) at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64) at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55) at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:92) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) Caused by: java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required" at java.base/sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2172) at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183) at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1362) at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1337) at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:246) at requests.Requester$$anon$1.readBytesThrough(Requester.scala:250) at geny.Readable.writeBytesTo(Writable.scala:57) at geny.Readable.writeBytesTo$(Writable.scala:57) at requests.Requester$$anon$1.writeBytesTo(Requester.scala:157) at requests.Requester.apply(Requester.scala:108)

@mdrijwan123
Copy link

Hey, look into my closed issue #59
Maybe it help you.

@half0wl
Copy link

half0wl commented Jan 9, 2022

@mdrijwan123 thanks for that post! Unfortunately, providing username/password credentials in the URL didn't work for me (seems that the library is using java.net.Proxy and passing in an InetSocketAddress, which only accepts a host/ip). I also subsequently realized that proxy auth never worked, so I went down a rabbit hole attempting to fix this in #100.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants