proxylab

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 telnet but under browser
  • curl --proxy [proxy ip]:[proxy port] [destination ip]

Socket

everything is file

  • getaddrinfo: convert string representation of IP to socket address struct
  • socket: create a file descriptor for network communication
  • bind: associate a socket with an IP address and port number
  • listen: make a socket listen mode
  • accept: server socket accept connection
  • connect: client try to connect to a socket address struct
  • close: close a socket fd

Your Proxy

  • should work on majority of sites : CNN, Twitch, NY Times, etc
  • No POST requirement, No https requirement
  • Proxy is both client and server

proxy

Tips

start small

  1. make a sequencial proxy
  2. make it multi-thread
  3. Cache web objects(individual objects rather than the whole page)

Test

  • ./driver.pl
  • work will real Internet in Firefox with your proxy
  • sprintf and sscanf are 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.1 requests, but your proxy should handle them and forward them as HTTP/1.0 requests.
  • The important request headers for this lab are the Host, User-Agent, Connection, and Proxy-Connection headers

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_clientfd and open_listenfd functions 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
2
$ tar xf proxylab-handout.tar
$ cat README