Let’s say you want to proxy http://localhost:4000 to somewhere else like http://another-host:4000. Then you can simply do that with socat(1).

socat TCP-LISTEN:4000,fork,reuseaddr TCP:another-host:4000