12.39

    1. +------+ +------+ +------+
    2. | |----->| |------>| |
    3. |client| |proxy | |server|
    4. | |<-----| |<------| |
    5. +------+ +------+ +------+
    6. as server as client

    proxy play with client as a server, with server as a client, interesting.

    the key point is when normal situation

    1. +------+ +------+
    2. | |----->| |
    3. |client| |server|
    4. | |<-----| |
    5. +------+ +------+

    HTTP request from client is something like

    1. GET / HTTP/1.1
    2. Host: address:port

    but with proxy, it’ll be

    1. GET http://address:port/ HTTP/1.1
    2. Host: address:port

    so proxy have to separate host from uri

    A.

    1. !INCLUDE "./code/12.39/proxy.c"

    B.

    move process into thread function

    1. !INCLUDE "./code/12.39/proxy-thread.c"

    how to benchmark:

    run proxy

    1. (cd chapter12/code/12.39; make && ./proxy)
    2. # or
    3. (cd chapter12/code/12.39; make && ./proxy-thread)

    open another terminal, start a local http server

    1. (python3 -m http.server 8000)

    open one another terminal, benchmark

    1. # -X means proxy, -n means how many requests, -c means concurrent
    2. (ab -X localhost:5000 -n 100 -c 10 http://localhost:8000/)