The principle of HTTP proxy and simple implementation of Python

An HTTP proxy is a network proxy server (Proxy Server), which can act as an intermediary between the client and the HTTP server. Its working principle is:

  1. When a client sends an HTTP request to the HTTP proxy, the HTTP proxy receives the request.

  2. The HTTP proxy forwards the request to the target HTTP server.

  3. The target HTTP server processes the request and generates a response.

  4. The HTTP proxy forwards the response to the client.

By using an HTTP proxy, clients can access resources on other servers without directly connecting to other servers. In this way, the real address of the client is hidden, and the HTTP proxy can also provide additional functions, such as caching web content, filtering content, and protecting privacy.

There are two forms of HTTP proxy, which are briefly introduced as follows:

The first is a common proxy , which is the most common proxy server and can proxy HTTP protocol network traffic. This kind of proxy only plays the role of "middleman". For the client connecting to it, it is the server; for the server to be connected, it is the client. It is responsible for transmitting HTTP messages back and forth between the two ends. Since HTTPS packets are encrypted and cannot be parsed, HTTPS requests cannot be proxyed.

The second is the tunnel proxy , which can encapsulate the client's request and response into a tunnel (Tunnel), and transmit the tunnel to the target server. Tunnel proxy can proxy network traffic of any TCP-based application layer protocol , including HTTP and HTTPS protocols.

Ordinary agent

The second web proxy principle is particularly simple:

Guess you like

Origin blog.csdn.net/qq_25439417/article/details/132528733