You could return your request handler from a method, and pass the remote IP to that method when you create it (will require a new function each time though). You could also make your request handler take both a request and the remote address every time it is called or you could update the request with the remote address before you pass it to your handler.
-- Johan Akka Team On Mon, Aug 1, 2016 at 5:54 PM, Zlatko Roncevic <[email protected]> wrote: > Hi, > > I need origin IP address in my request handler, but I don't know how to > add this parameter ... > > Code is here > > Source<IncomingConnection, CompletionStage<ServerBinding>> serverSource > = > Http.get(system).bind(ConnectHttp.toHost(host, port), materializer); > > binding = serverSource.to(Sink.foreach(connection -> { > logger.info("Accepted new connection from {} " + > connection.remoteAddress()); > > > connection.handleWith(Flow.<HttpRequest>create().mapAsync(1, > requestHandler), materializer); > > } > )).run(materializer); > > binding.handle((ok, ex) -> { > if (ok != null) { > logger.info("Server listening on {}:{}",host, port); > return ok; > } else { > logger.error("Problem during start: {}", ex); > return -1; > } > }); > > > //Request handler > > final Function<HttpRequest, CompletionStage<HttpResponse>> requestHandler > = new Function<HttpRequest, CompletionStage<HttpResponse>>(){ > @Override > public CompletionStage<HttpResponse> apply(HttpRequest request) throws > Exception { > logger.trace("Request from : {} {} {}", request.method(), > request.getUri(), request.getHeaders()); > //I would like to have connection.remoteAddress() value here > ... > > > I'm missing something, what is right approach to put initial parameters to > flow? > > Thanks ! > > Regards > > Zlatko > > > > > > -- > >>>>>>>>>> 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. -- >>>>>>>>>> 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
