Proxy Server Development
I try to develop proxy web server and i need some help.
The use case of my application: there is proxy server and some independent resources. Proxy server is installed into second level domain (for example hello.com), and all resources should be installed into sub-domains (for ex: resource1.hello.com, resource2.hello.com). So all requests to my resources should be processed by proxy at first. And then if processing is OK request should be passed to my resource
Proxy server provides next functionality: caching, authorization, etc. But it doesn't matter. I am interested in Proxy Server architecture. How it works with http client requests.
I have next ideas how to develop this proxy:
1) Proxy server works like servlet filter. So, client sends http-request directly to web resource and proxy server intercepts it. If request processing and authorization were successful, proxy forwards client request to required web resource.
Architecture in this case looks like: Client <-proxy-> Resource. Resource works with client request directly and returns response directly to client.
But i don't know how to configure this. No ideas how to tell proxy server, that it should intercepts all request to all sub-domains.
Example: client wants to access resource1.hello.com/myPage.jsp. He sends http request to resource1.hello.com/myPage.jsp and it is intercepted by proxy server
2) All client requests come to proxy server - facade. And all web resources are not accessible for client. For example they are hidden by firewall.
So, when request comes, proxy server parses http-request, extracts destination address and creates new inner http request, sends it to resource destination and then returns received inner-http-response to client.
Architecture in this case looks like: Client <-> Proxy and inner request: Proxy <-> Resource
Example: client wants to access resource1.hello.com/myPage.jsp. He sends http request to hello.com/resource1/myPage.jsp, and proxy server determines destination address: "resource1/myPage.jsp", and sends new http request to resource1.hello.com/myPage.jsp.
There is one problem here: all internal links in resources should be prepared according to some scheme. For example, resource1.hello.com/myPage.jsp should be transformed to hello.com/resource1/myPage.jsp. It is high issue, i think. The use case of my proxy server is that somebody can write resource and just put it under my proxy server and it should works. As result links should be transformed before resource will be in use.
It is all. And ideas? I will be glad to get any help. May be i need to know more about http protocol and how http request is passed through second level domain to sub-domains.