Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When a proxy receives a connection how does the proxy know where to forward the request to?
For example in Java we can set a system property for proxy.
So we set the IP of the proxy and the request is send to the proxy, but how does a proxy know where to forward the actual request to?

share|improve this question

There are a number of types of proxies, and each uses a different approach to communicate to the proxy server what it wants to do.

HTTP proxies understand HTTP only, and do not try to proxy packets, but instead HTTP commands like connect, get, post, etc. They create an entirely new packet addressed at the lower layers from themselves to the destination server. When a client initiates a connection, the first packet of the http flow contains the CONNECT verb. the proxy recieves it, does a dns lookup on it if needed, and builds a packet to send to the remote server using the http commands and data flow from the packets it receives from the client.

SOCKS proxies perform tunneling above the session layer, so the client configures a layer 5 header which tells the proxy where you want to connect, transport protocol info, and passes any authentication the proxy requires. The client places the Layer 6/7 datagrams into the layer 5 segment's data region, and sends it to the proxy. the proxy receives it, creates a new packet (without a SOCKS header) addressed to the remote server, places the layer6/7 data units from the client packet into the new packet, and sends it to the destination server. SOCKS proxies don't work for all upper layer protocols, but they will proxy most lower layer protocols including tcp and udp.

share|improve this answer
CONNECT is standard header? – Jim Jul 21 '13 at 22:05
its an HTTP command. if you look at HTTP as a layer 7 protocol and ignore all the rest of the network stack, HTTP is just a set of Text commands and responses. see here for the standard HTTP commands: . it may help to note that if you use telnet to connect to a web server at port 80, you could issue a command like 'GET \index.html HTTP/1.1' it will return the markup of the page index.html. a CONNECT command tells the client to connect to a server. after that, the client can GET, POST, or whatever. – Frank Thomas Jul 22 '13 at 2:25
to answer your question precisely though, no, HTTP commands and their responses are the actual data of the packets (they go in the layer 7 datagram in the data region from an encapsulated point of view) rather than fields in a well formed header. – Frank Thomas Jul 22 '13 at 2:56
a CONNECT command tells the client to connect to a server. after that, the client can GET, POST, or whatever So the proxy keeps some kind of session for each client? – Jim Jul 22 '13 at 17:50
TCP handles session. at Layer7 you can think of a connection like a tube you yell through to talk to a guy in the next apartment. the connection exists as an IO stream, and by writing to that stream, you are sending a communication, and you read data off it to read a response. how that breaks down into packets is unimportant at this level. This is why TCP protocols like HTTP are called connection-orriented. once the connection is established, you just read and write data to the network stream as needed. – Frank Thomas Jul 22 '13 at 18:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.