The first one is achieved by a fixed module. In order to deal with all requests at the same time,several processes in system shall be started. First one is known as the parent process or main process. By binding the socket in specific port and three shakes, the main process listen therequest from the client. If there’s one, there will be a new socket and a child process will becreated. In the child process, the old socket will be closed and the new socket will process allrequests. In the parent process, the new socket will be closed since they won’t be used any morewhereas the old socket will keep alive to listen to new request.However, the key process in this program is to process the content to send and achieve. Generallyspeaking, there’re two key processes. The first one is between receiving the request and sendingrequest. The second is between receiving the response and sending the response.In first process, according to the definition of HTTP header in RFC 2616, we need to check the proxy authentication of using a proxy. Some commands in HTTP should be found (ProxyAuthentication: Basic …). If there’s not such a command, the proxy server should reject to offer service to the client by sending “HTTP/1.1 407 …” Then, the browser of client will ask user toenter username and password. A command “Proxy-Authentication” will be append to HTTPheader afterwards. If the username and password fits perfectly, user may start to use the service.Furthermore, for the process in response (to complement the optional function: adding Proxy intitle of webpage), the text response is expected. To achieve this, the command “Accept-Encoding”should be deleted and then the application will receive text response as a result. Furthermore, weneed to analysis the host name and port number in order to fill in the socket address correctly. TheIP address is needed as well by querying DNS server as well.In response process, we can get the throughput though browser and the responding time bycounting the time after sending request until receive the first response. The throughput can becounted by adding the amount of information received. If optional function is triggered by portnumber the user chosen (port number larger than 8000), the string “Proxy:” should be put into the packets, and the “Content-Length” should be modified or deleted if there’s one.
The key algorithm we making is both about string operation. The first one is adding a string or deleting a string in a specific string. The second one is picking out the domain name of the host.Both operations are based on pointer operation. A special bug-fix method will be involved as wellin this part.The first algorithm is implemented by finding the location of operation with pointer variable. Thefunction strstr in <string.h> is the most common way to find it. The function strstr returns the pointer of a specific string appears first time. By assigning that to a pointer variable, we can easilyget the precious location in a string. However, to store the modified header we need to allocate a