-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
40 lines (34 loc) · 1.91 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
P2 - Implementing a Simple HTTP Web Proxy
Dennis Levin, Matt Jordan
April 28, 2016
Files: proxy.cpp, proxy.h, Makefile, readme.txt
Run proxy with ./proxy server_port
Proxy can be quit by signaling CTRL-C
BROWSER SETTINGS:
Firefox: Specify proxy and change the following settings in about:config
network.http.proxy.keepalive = false
network.http.proxy.pipelining = false
network.http.proxy.version = 1.0
DESIGN & IMPLEMENTATION HIGHLIGHTS:
PROXY:
Handles concurrent connections and requests by using the producer-consumer pattern.
The main thread accepts client connections and produces socket file descriptors.
A thread pool of 30 threads then consumes the file descriptors out of a synchronized
queue. The client request string is processed/parsed and forwarded to the target
server. The server response is forwarded unprocessed back to the client.
IMPLEMENTATION DESIGN DECISION:
The thread pool consists of 30 threads. A semaphore and mutex lock are used for
synchronizing the consumer buffer among the threads. On consume, the entire
request message from the client is loaded into a buffer. The buffer is then
processed in order to extract the request command, path, HTTP version and any
headers that accompanied the request. The headers, separated by CRLF, are
stored in a map with key being the type of header (e.g. Content-Type). The map
is then checked for missing or incorrect headers. Connection is changed to close
and a Host header is added if missing. A full request string is then build using
stringstream. The request string is written to the webserver socket and the
response is immediately forwarded back to the client without parsing.
For any other request command than GET, the proxy will return 500 Internal Error.
If the client's browser is not correctly configured to only send HTTP/1.0
requests, the proxy will change the request line from HTTP/1.1 to HTTP/1.0.
LIMITATIONS:
Secure content (https) will not be loaded