# ch06: Proxies

![6.代理](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh1pyk8usj310v0u0gyt.jpg)

## 1. Web Intermediaries

HTTP proxy servers are both web servers and web clients.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh1r7v4ctj314m0fcwiv.jpg)

### 1.2 Private and Shared Proxies

Proxies dedicated to a single client are called _**private proxies**_.

Proxies shared among numerous clients are called _**public proxies**_.

### 1.3 Proxies Versus Gateways

Proxies connect two or more applications that speak the same protocol.

While gateways hook up two or more parties that speak different protocols.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh1ui7qr6j314m0lsaek.jpg)

## 2. Why Use Proxies?

### 2.1 Chile Filter

The proxy permit unrestricted access to educational content but forcibly deny access to stites that are inappropriate for children.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh1vw45itj314w0lyaje.jpg)

### 2.2 Document Access Controller

Proxy servers can be used to implement a uniform access-control strategy across a large set of web servers and web resources and to create an audit trail.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh1z05pmdj314w0outfg.jpg)

### 2.3 Security Firewall

Use proxy servers to enhance security.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh20xa5o5j314i0my10g.jpg)

### 2.4 Web Cache

Proxy caches maintain local copies of popular documents and serve them on demand, recuding slow and costly Internet communication.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh22rdbuhj314w0pgn3q.jpg)

### 2.5 Transcoder

Proxy servers can modify the body format of content before delivering it to clients.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh23l6lhcj314q0jc0z0.jpg)

### 2.6 Anonymizer

Anonymizer proxies provide heightened privacy and anonymity, by actively removing identifying characteristics from HTTP messages.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh24n6wg5j314m0hswkn.jpg)

## 3. Where Do Proxies Go?

* How proxies can be deployed into networks?
* How proxies can chain together into hierarchies?
* How traffic gets directed to a proxy server in the first place?

### 3.1 Proxy Server Deployment

You can place proxies in all kinds of places, depending on their intended uses.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh26w5hqpj30u00zy7ga.jpg)

* **Egress Proxy**: stick proxies at the exit points of local networks to control the traffic flow between the local network and the greater Internet.
* **Access(ingress) Proxy**: proxies are often placed at ISP access points, processing the aggregate request from the customers.
* **Surrogates(reverse proxies)**: proxies frequently are deployed as surrogates at the edge of the network, in front of web servers.
* **Network Exchange Proxy**: proxies can be placed in the Internet peering exchange points between networks.

### 3.2 Proxy Hierarchies

Proxies can be cascaded in chains.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh2c15rg8j315c0b6jtn.jpg)

### 3.3 How Proxies Get Traffic

* _**Modify the client**_: configure the client to use proxy;
* _**Modify the network**_: configure the router to intercepts and redirects traffic to proxy;
* _**Modify the DNS namespace**_: configure the proxy to be the web server;
* _**Modify the web server**_: web server redirects the request to proxy.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh2duovecj315i0retfs.jpg)

## 4. Tricky Things About Proxy Requests

Some tricky and much misunderstood aspects of proxy server requests.

### 4.1 Proxy URIs Differ from Server URIs

When the client is not set tot use a proxy, it sends the partial URI.

When the client is set to use a proxy, it sends the full URI.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh2x4kk1hj314s0ggjuv.jpg)

### 4.2 The Same Problem with Virtual Hosting

Virtually hosted web servers share the same physical web server among many web sites.

When a request comes in for the partial URI /index.html, the virtually hosted web server needs to know the hostname of the inteded web site.

* Explicit proxies solve the problem by requiring a full URI in the request message.
* Virtually hosted web servers require a **Host header** to carry the host and port information.

### 4.3 Intercepting Proxies Get Partial URIs

Client will not know it is talking to a proxy.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh31ixcd2j314y0o679i.jpg)

### 4.4 Proxies Can Handle Both Proxy and Server Requests

General-purpose proxy servers should support both full URIs and partial URIs in request messages.

Rules:

* If a full URI is provided, the proxy should use it.
* If a partial URI is provided, and a Host header is present, the Host header should be used to determine the origin server name and port number.
* If a partial URI is provided, and there is no Host header, the origin server needs to be determined in some other way:
  * If the proxy is a surrogate, standing in for an origin server, the proxy can be configured with the real server's address and port number.
  * If the traffic was intercepted, and the interceptor makes the original IP address and port available, the proxy can use the IP address and port number from the interception technology.
  * If all else fails, the proxy doesn't have enough information to determine the origin server and must return an error message.

### 4.5 In-Flight URI Modification

Proxy serves need to be very careful about chaning the request URI as they forward messages.

## 5. Tracing Messages

A request may go through many proxies, sometimes we need to know what proxies a message go through.

### 5.1 The Via Header

#### 5.1 Via syntax

```
Via: 1.1 proxy-62.irenes-isp.net, 1.0 cache.joes-hardware.com
```

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh3ddhrzuj31580f6gp6.jpg)

#### 5.1.2 Via request and response paths

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh3edg71wj314m0gwtbe.jpg)

#### 5.1.3 The Server and Via headers

The Server response header field describes the software used by the origin server.

```
Server: Apache/1.3.14 (Unix) PHP/4.0.4
Server: Netscape-Enterprise/4.1
Server: Microsoft-IIS/5.0
```

### 5.2 The TRACE Method

TRACE method just likes the traceroute.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh3gq52wbj314o0r47ax.jpg)

#### 5.2.1 Max-Forwards

Max-Forwards limits the number of proxy hops for TRACE and OPTIONS request.

## 6. Proxy Authentication

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh3j2iwghj30x50u07cx.jpg)

## 7. Proxy Interoperation

If a proxy is unfamiliar with a method, it should try to forward the message to the next hop, if possible.

### 7.1 OPTIONS: Discovering Optional Feature Support

OPTIONS method lets a client discover the supported functionality of a web server or of a particular resource on a web servesr.

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ggh3n95xoij314i0dctb1.jpg)

### 7.2 The Allow Header

The Allow entity header field lists the set of methods supported by the resource identified by the request URI, or the entire server if the request URI is \*.

```
Allow: GET, HEAD, PUT
```
