Final lab : Proxy Lab
Watch the video
Web test tools
Telnet
- no security & manually construct requests
telnet [ip addr] [port number]- telnet requests always end with a blank line
cURL
- above
telnetbut underbrowser curl --proxy [proxy ip]:[proxy port] [destination ip]
Socket
everything is file
getaddrinfo: convert string representation of IP tosocket address structsocket: create a file descriptor for network communicationbind: associate a socket with an IP address and port numberlisten: make a socket listen modeaccept: server socket accept connectionconnect: client try to connect to asocket address structclose: close a socket fd
Your Proxy
- should work on majority of sites : CNN, Twitch, NY Times, etc
- No
POSTrequirement, Nohttpsrequirement - Proxy is both client and server

Tips
start small
- make a sequencial proxy
- make it multi-thread
- Cache web objects(individual objects rather than the whole page)
Test
./driver.pl- work will real Internet in Firefox with your proxy
sprintfandsscanfare thread-safe but not async-signal safe
Read the writeup
Part I: Implementing a sequential web proxy
- All lines in an HTTP request end with a carriage return,
‘\r’, followed by a newline,‘\n’. Also important is that every HTTP request is terminated by an empty line:"\r\n". - Modern web browsers will generate
HTTP/1.1requests, but your proxy should handle them and forward them asHTTP/1.0requests. - The important request headers for this lab are the
Host, User-Agent, Connection, andProxy-Connectionheaders
Part II: Dealing with multiple concurrent requests
The simplest way to implement a concurrent server is to spawn a new thread to handle each new connection request.
- Note that your threads should run in detached mode to avoid memory leaks.
- The
open_clientfdandopen_listenfdfunctions described in the CS:APP3e textbook are based on the modern and protocol-independent getaddrinfo function, and thus are thread safe.
Part III: Caching web objects
Get Start
1 | $ tar xf proxylab-handout.tar |