Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. The requested Web page name contains the Web server name www.foo.com and the requested file on that server /mumbo.html. In this case, your proxy server should make a TCP connection to Web server www.foo.com at the default port 80 and ask for file /mumbo.html by sending the following request:
  2.  
  3. GET /mumbo.html HTTP/1.1\r\n
  4.  
  5. Connection: close\r\n\r\n
  6.  
  7. After sending a request to the “real” Web server, an HTTP response including the requested file will be received at the proxy server. The proxy server should then forward the content to the client. There are three parts in an HTTP response message: the status line, the response headers, and the entity body. The status line and response headers are terminated by an empty line (or an extra “\r\n”). In short, an HTTP response message may look like the following:
  8.  
  9. HTTP/1.1 200 OK
  10.  
  11. Date: Thu, 24 Jan 2013 15:29:52 GMT
  12.  
  13. Content-Type: text/html
  14.  
  15. Server: Joe's Web proxy server
  16.  
  17. Connection: close
  18.  
  19. ... ... <content of the main.html>
  20.  
  21. The status line and most of the header fields should be forwarded to the client without
  22.  
  23. modification.
  24.  
  25. The server should be able to handle multiple simultaneous service requests in parallel. This means that the Web proxy server is multi-threaded. In the main thread, the server listens at a fixed port. When it receives a TCP connection request, it sets up a TCP connection socket and services the request in a separate thread.
  26.  
  27. The “Connection: close” setting in the above examples serves an important role --- disabling the persistent connection feature in HTTP 1.1. A persistent connection allows multiple Web requests to flow through a single TCP connection. However, the support for persistent connections is somewhat challenging and it is not required for this assignment. Note that when you test your proxy server through a standard Web browser, the “Connection: close” setting will likely not be in the HTTP request. Your proxy server can insert this setting into the request before forwarding it to the Web server so that the persistent connection is turned off.
  28.  
  29. Program Skeleton
  30.  
  31. Here we provide a hint on what the program skeleton may look like. You are, however, not required to design your program this way.
  32.  
  33. Main routine {
  34.  
  35. Parse the command line input (server port number);
  36.  
  37. Create a server socket listening on the specified port;
  38.  
  39. For each incoming client socket connection {
  40.  
  41. Spawn a worker thread to handle the connection;
  42.  
  43. Loop back to wait for/handle the next connection;
  44.  
  45. }
  46.  
  47. }
  48.  
  49. Worker thread routine {
  50.  
  51. Read the request line and header fields until two consecutive new lines;
  52.  
  53. (Note that a new line can be a single "\n" or a character pair "\r\n".)
  54.  
  55. Examine the first line (request line);
  56.  
  57. If the request method is not "GET" {
  58.  
  59. Return an error HTTP response with the status code "HTTP_BAD_METHOD";
  60.  
  61. }
  62.  
  63. Make TCP connection to the "real" Web server;
  64.  
  65. Send over an HTTP request;
  66.  
  67. Receive the server's response;
  68.  
  69. Close the TCP connection to the server;
  70.  
  71. Send the server's response back to the client;
  72.  
  73. Close the connection socket to the client.
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement