On 19.03.2020 04:18, HeeGu Lee wrote:
I was tasked with writing a web application that needs to forward a http
request to each server after checking certain headers.
Of course I can use a library like apache http client to reconstruct and
send the data.
But if you think about it, this is a very unreasonable and bad way.
No, it is pretty much the only way that makes sense. Well, at least if you want to do this
First : there is no code in tomcat that does any kind of "proxy/forwarding" function, nor
(to my knowledge) any plan to add such code.
See the first phrase of the tomcat on-line documentation, at
So any such function must be implemented by a web application (servlet) running under
tomcat, and I guess that whoever asked you to create such a servlet knew this, and that's
why they asked you to do it this way.
You could also search for already-existing software which does this, for
example here :
or here :
Suppose you need to forward a request that uploads a 100 mega file.
To forward this, once the servlet receives it as an object, the server
memory is already reduced.
Couldn't Servlet Engine check and pass only a few headers and pass it in
See above. If you create yourself a "proxy servlet", you are allowed to do in it what you
want. As soon as tomcat receives the original request, its headers are available to your
servlet for examination, and you can start a connection to the target back-end server.
You can then read the request content body in any way you want, and send it to the target
back-end in any way you want. The only thing is, you can read ("consume") the request
body only once, so if you need to "distribute" the same request to several back-ends, you
will have to do some local buffering anyway.
Even if it is not the above example, I think the servlet may have the
ability to have it in a raw state or to return it, like the request strings
sent to telnet.
I think it would be great if this could be supported by the servlet engine
As indicated by the tomcat description, it is not really tomcat's purpose to be a reverse
proxy. There are other webservers which already contain proxying code (like Apache
httpd), and which may be a better starting point to do this.
Thank you for reading!
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org