Am 6. Mai 2014 bei 04:40:41, Ranjit Kumar (ran8...@gmail.com) schrieb:
I would like to know how can I implement a proxy server in Vert.x (preferably using the groovy API) which is transparent to the user meaning that when a user enters "http://google.com" the server should be able to serve all the image, js, css files together with being able to handle any ajax calls. Also I should be able to parse the HTML content of the page before displaying it to the user. If the implementation is too big, kindly provide pointers as to how I should get started.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi,
I have looked at http proxy with vert.x, I think I can give some pointers what you have to do (and what doesn't work).
First of all, to implement a http proxy, you have to do your request parsing yourself, since you currently do not have a proxy functionality available as a httpServer (i.e. the server only understands local urls starting with /).
You can use a squid to provide the proxy functionality and then use a redirecter script to redirect to your local http server, then you can basically use the proxy example from the examples source to do the actual proxy operation. For this to work, you can proxy GET and POST methods, so that any request including AJAX calls should work.
When you implement a https proxy, the situation is quite different, if you only want to forward the ssl requests to the correct server, you can process the CONNECT method and do a simple Buffer forwarding (or Pump?) to the origin server. If you however want to look at the request or the result or want to modify the request in any way, you need the ssl "man-in-the-middle" attack which means that the browser will complain about the certificate, but that should be possible also. In this case you have to do the http request parsing yourself as well, if you want to change anything in the request.
bye, Alexander
On Tuesday, May 6, 2014 11:15:06 AM UTC+2, Ranjit Kumar wrote:The proxy example given here redirects requests occurring at a specific URL (http://localhost:8080). Instead I want to redirect all URL requests to the browser. For example I have created an HTTP server on port 8080 and added localhost:8080 as proxy in firefox so all requests are directed to this server. Now I can read the requested URL from req.uri (or req.absoluteURI). How do I return the HTML at this particular URL to the browser? Also how can I add support for AJAX calls as well?
On Tuesday, May 6, 2014 1:39:20 PM UTC+5:30, Norman Maurer wrote:Did you check the examples?
--
Norman Maurer
i also had a look at this & asked a question in the forum about the design of the httpclient, but there's no answer.
by the way it works you will need to create for each request (or each host) a client instance, because it bounds to a host/port, seems inefficient for a non-reverse proxy.
Yes that is what I thought. But the part I am stuck at is "implementing the absolute URI connection". I tried dumping the html stored at the URI to a file and then returning that file. It works as far as css/js/png/jpg files are concerned. but a page is not just these things. A lot of pages call APIs on other sites plus there are ajax calls etc.
Would that work with web-sockets as well?I was trying to get web-sockets to go through a reverse proxy and opening/communication worked fine but when either the server or client disconnected it didn't go across and just stopped at the proxy.
--