#C++ HTTP PROXY
##HOW TO USE
- Copy all the files in one directory.
- In the terminal:
- cd /path/to/code/
- The server should start listening for connections.
- Connect to the server using a web client or telnet.
- Send a HTTP request, like: GET http://www.google.com/ HTTP/1.0
- The headers and HTML of the Google homepage will be displayed on the terminal screen.
##EXIT THE SERVER
- You can exit the server by simply using
Ctrl + C
- Or connect to the server using telnet:
- press Carriage Return(Enter) twice
- It does not handle concurrent requests, only sequential requests.
- Only HTTP/1.0 implemented.
- Only “GET” method is implemented.
- Connection: keep-alive not implemented.
- Accepts “GET” requests. Otherwise, responds back with a 501(Not Implemented) error.
- Flexibility in choosing the server port for the server.
- Accepts all the available formats for HTTP headers. If something goes wrong, responds with a 400(Bad Request) error.
- Works with HTTP/1.0 Also accepts HTTP/1.1 requests, but forwards the request to remote(origin) server with HTTP version 1.0
- Closes the client and remote server connection after a request is complete.
- Parses the given HTTP request, separates the different parts of the requests into a map of (string, string) to make a well formatted string to be forwarded.
- NOT IMPLEMENTED Proxy works behind another proxy (without authentication). NOTE: Proxy details have to be specified in the code using a macro, file: http_proxy.cpp
http_proxy.cppcontains the flow of the program, i.e.,
- Make a socket to listen to with the port number provided as an argument.
- Accept connection from a client and receive a HTTP request.
- Parse the request for remote server name, port (optional), path and other headers.
- Make a well formatted request to be forwarded to the remote server.
- Receive response from the remote server, which may even contain errors.
- Forward the response to the client.
- Close the connection.
- Waits for another connection from a client. (goes back to step II)
eventLogger/eventLogger.hppcontains the functions to log events with their timings to the standard input and standard error.
HttpHeadersParser/http_requests_parser.hppcontains a class which handles HTTP requests. Given a request,
- It first tokenizes the string using “\r\n” or “\r” as a delimiter.
- Reads the first line of request for the HTTP method, URI, HTTP version.
- Reads the subsequent lines to form a map of headers and their values.
- Finally, forms a well formatted string of the request.
server/proxy_server.hppcontains the functions to setup a socket and connect to it. It gracefully handles all the errors internally in making a connection. It also contains functions to receive and send message through the socket in the form of string or unsigned character (overloaded functions). It can even set a timeout on the sockets.
client/proxy_client.hppcontains the functions to handle the part of proxy to connect to the remote server. It helps in forwarding the request and receiving the response from the remote server.
makefilecontains the required commands/dependencies to compile and make an executable.