Connect to external HTTP server from Netty - http

I need some help with understanding how to write HTTP router, which recognizes HTTP header as routing criteria. I found the link https://github.com/cgbystrom/netty-tools/blob/master/src/main/java/se/cgbystrom/netty/http/router/RouterHandler.java which seems to do the routing itself. But now it is not clear, how to
connect to another HTTP server
send HTTP request
wait for HTTP response
forward the HTTP response to client
can somebody please give me some explanations?

http://static.netty.io/3.5/xref/org/jboss/netty/example/proxy/package-summary.html
the example of proxy server in Netty, essentially what I wanted

Related

I need http port forward proxy server golang

I need http port forward proxy server golang
Be able to provide Rest http api
Kind of like
PortForward Traffic Forwarding
Please tell me the program that can be used directly.
thanks

How can a Netty Server porcess a client request using another Netty Client for Http2 Proxy Server

My requirement is if a browser sends the request to ServerBootStrap then the ServerBootStrap creates BootStrap (Client) and that client connects with a proxy server.
The problem here is to connect with Proxy Server we need to send first HTTP CONNECT method to open a tunnel from Proxy and BootStrap (Client) and then whatever request comes from Browser to Server, the server will send BootStrap(client) and all the communication should happen.
This will look like
Browser ->ServerBootStrap(Server)->BootStrap(Client)->ProxyServer(HTTP2)
Can somebody tell me how do I implement this for Http2?
How do I send Http CONNECT from a Handler for the First time while Client instantiating and If CONNECT gets 200OK from Proxy Server I will to remove Handler from channel pipeline?
Can we explicitly call any HTTP CONNECT request while adding a handler in Pipeline and getting the response to check the status?
--Can somebody answer ?

Rewrite WebSocket messages via Nginx?

Is it possible to rewrite the content of a websocket message proxied through Nginx?
For example, say I've sent a message with the contents JSON.stringify({ auth: 'someIdKey' }). On Nginx, I would to substitute the value of someIdKey to someJwt, then forward it to the proxied upstream resource. I'd also want to do the reverse translation when the upstream resource sends out messages back to the client.
I know how to do this (and am doing this) for HTTP requests, rewriting custom headers to do an on-the-fly translation, but I'm not sure how to approach carrying over the pattern to websocket communication.
I'm using OpenResty as my Nginx distribution and am passably-ok at Lua scripting.
Would appreciate any ideas/help.
You can use https://github.com/openresty/lua-resty-websocket module.
It has both server and client side non-blocking API. So you can program anything you want.

What is the best way to redirect network requests?

I've written my own HTTP Server, but given certain criteria, I want to redirect some requests made to my server to another server running on the same machine. For example, I may want to redirect all requests to "/foo/*" to be handled by an apache server I also have running. What is the best way to do this?
The only way I can think of doing this is by running apache on a different port, and then making a completely new network request from my server to localhost:1234 (assuming apache is running on port 1234) with the same exact request headers and body, and then take the response and have my server send that back to the client.
That seems like a kind of hacky, roundabout way of accomplishing this though, and I'm sure this is a problem that is tackled by every major website. Is there a certain technology or protocol for doing this that I just haven't heard of?
Thanks a lot!
Edit: Just to be clear, the client should only make one network request for all this, rather than having my server return a 3xx response
HTTP runs over TCP. The Apache server can't just send the required response to a client who hasn't asked for it. The client has asked YOUR HTTP server for the data and so it must be the one to send a response. The client is probably behind a firewall and, as such, the Apache server can't even establish a TCP connection with it (incoming connections are usually blocked).
If your server takes the clients request, forwards it to the Apache server, gets the response from the Apache server and forwards it to the client, it's acting as a proxy server (a middleman). This won't be redirection.
The only sensible way to do this would be to have the client make two network requests.

Anyone aware of a simple example of a Netty HTTP server which supports persistent HTTP connections?

Can anyone provide an example of a simple HTTP server implemented using Netty, that supports persistent HTTP connections.
In other words, it won't close the connection until the client closes it, and can receive additional HTTP requests over the same connection?
This is exactly one of the things their sample http code demonstrates.

Resources