Handling HTTPS with Akka-http

285 views
Skip to first unread message

Bassam Khallaf

unread,
Apr 13, 2016, 6:11:11 PM4/13/16
to Akka User List
Dear Gents,

I was creating a small proxy to intercept all local http requests, then authorize them with the remote proxy. Here is the code snippet:

Source<IncomingConnection, CompletionStage<ServerBinding>> serverSource =
                Http.get(system).bind(ConnectWithHttps.toHost("localhost", LOCAL_PORT), materializer);
        Authorization authorization = Authorization.basic(USERNAME, PASSWORD);

        Flow<HttpRequest, HttpRequest, NotUsed> applySecurity =
                Flow.of(HttpRequest.class)
                    .map(request -> request.addHeader(authorization));

        Flow<HttpRequest, HttpResponse, CompletionStage<OutgoingConnection>> forwardToProxy =
                Http.get(system).outgoingConnection(ConnectWithHttps.toHost(PROXY_ADDRESS, PROXY_PORT));

        Flow<HttpRequest, HttpResponse, NotUsed> handler =
                Flow.of(HttpRequest.class)
                   .via(applySecurity)
                .via(forwardToProxy);


    serverSource.to(Sink.foreach(conn -> {
             System.out.println("Accepted new connection from " + conn.remoteAddress());
             conn.handleWith(handler, materializer);
                }
 )).run(materializer);

 I need to handle Https requests also. But I always get this error:

[WARN] [04/14/2016 00:07:28.480] [MyActorSystem-akka.actor.default-dispatcher-13] [akka.actor.ActorSystemImpl(MyActorSystem)] Illegal request, responding with status '400 Bad Request': Request is missing required `Host` header: 'Host' header value of request to `eg.linkedin.com:443` doesn't match request target authority: Host header: Some(Host: eg.linkedin.com:443)



I've tried to use "ConnectWithHttps" instead of "ConnectHttp" but it didn't. I couldn't find any example related to Https
Any idea, thanks?

Regards,
Bassam


Bassam Khallaf

unread,
Apr 15, 2016, 9:58:02 AM4/15/16
to Akka User List
Hello,

Is there any tutorial or example related to Https with akka-Http[java]?

Thanks

Akka Team

unread,
Apr 20, 2016, 4:57:03 AM4/20/16
to Akka User List
Hi Bassam,

The client does not fully support proxies, especially when it comes to Https: see https://github.com/akka/akka/issues/16853

-Endre




--
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

bassam....@gmail.com

unread,
May 5, 2016, 10:02:26 AM5/5/16
to Akka User List
Hi Endre,

Thanks for your reply, 
What I'm trying to do is a relay or intermediate proxy to intercept all HTTPS requests on my machine then authorize it with organization real proxy then return the response back to origin requester. I wanna do this to remove all the hassle of configuring all build tools with username/password like: sbt, maven, npm and so on. I just want to refer to localhost with some port and put the credentials only in one place, the relay.

Any suggestion? 

Thanks for your time,
Bassam
Reply all
Reply to author
Forward
0 new messages