Virtual Network System (VNS)

Contents

  • 1 Address in use Errors
  • 2 Internet Explorer Problems
  • 3 Broken Images
  • 4 Hostless Request
  • 5 HTTP/1.1 Requests
  • 6 Bad Requests
  • 7 Internal Error (500)?
  • 8 Request/Response Line length?


Address in use Errors

Q) Why do I keep getting the error "Address already in use" when I try to run my proxy server?
A) This error typically means that there is already a socket bound to the same port that you are attempting to bind to. If you're testing your proxy on one of the cluster machines, this may just mean that another student is running a proxy on that port already. Otherwise, it could mean that a proxy shutdown without properly closing the port that it was running on; if you bind to, say, port 8000 and then kill your proxy without closing the port, it may take a few minutes for the operating system to notice that the port is no longer in use and make it available again. Try running your proxy again, binding to a different port (this is one reason why running with hard-coded port numbers is a bad idea).
If your proxy is looping forever to serve requests and being stopped with Ctrl-C, you might want to try registering a handler for the SIGINT signal to clean up after your proxy- it can greatly reduce instances of your favorite port number becoming 'stuck'. Take a look at the signal (2) man page for details. Another option is to set the SO_REUSEADDR option to allow the proxy to re-use an address that is already in use; look at the setsockopt man page for more information

Internet Explorer Problems

Q) Internet Explorer seems to sometimes hang when I attempt to use it with my proxy. Is this a problem with the browser, or my proxy?
A) It could be either. Internet Explorer is not quite as friendly as Firefox in terms of accommodating proxy servers that have limited capabilities (such as not supporting Connection Keep-Alive or HTTP 1.1). First of all, make sure you've done the following:
  1. Under Internet Options, select 'Advanced'
  2. Scroll down to 'HTTP 1.1 Settings' and uncheck 'Use HTTP 1.1 through proxy connections'.
If this doesn't correct the problem, try configuring Firefox to use your proxy. If the problem appears with both IE and Firefox, it is likely your proxy that is the source of the trouble. If your proxy works with Firefox but not Internet Explorer, IE is likely the culprit.

Broken Images

Q) My proxy seems to work for web pages, but all of the images on the page are coming up broken. What's going on?
A) Remember that your proxy has to handle both text data- like web pages and HTTP requests- and binary data- like image files and downloads. You can easily run into problems if you try to use functions like fputs to send data to the client- it will work correctly for text data, but will likely fail to work correctly for binary data. Use the read/write fread/fwrite functions instead. Another possible cause for this problem could be that you have a single-threaded proxy, and it is missing subsequent HTTP requests while it is serving the request for the main page. Multi-threading is not required for this assignment- see the grading notes on the assignment page if you have questions.

Hostless Request

Q) I got a request that had no host- just a file path. What should I do?
A) A misconfigured client may fail to send the entire URL for the requested resource to your proxy- that is, it sends something like:
GET /index.html HTTP/1.0
as the initial request line instead of:
GET http://www.yahoo.com/index.html HTTP/1.0
In this case, you can't reasonably expect to be able to handle the client's request- you don't even know what server to contact. It's a bad request, so you should send an appropriate error code and message.

HTTP/1.1 Requests

Q) How should I handle requests from a client that uses HTTP/1.1 instead of HTTP/1.0?
A) Unless they are trying to use a method that isn't supported by HTTP/1.0, you should go ahead and process their request to the best of your ability. You're not required to support keeping the connection alive for HTTP/1.1 clients- they are required by the RFC to be able to handle their connection being closed by either end at any time. So parse their request, send out a HTTP/1.0 request to the remote server, and return their data using HTTP/1.0 as normal. You should return error 501 (Not Implimented) for valid HTTP/1.1 methods that are not covered by RFC 1945.

Bad Requests

Q) What error should I return if I get a request from the client that I can't parse?
A) You should send status code 400 for any malformed request that you are unable to process.

Internal Error (500)?

Q) When should I send status code 500 (Internal Error)?
A) You should only send code 500 for problems within the proxy that prevent you from replying to the client- for instance, if you are unable to allocate additional memory or open a file that you need in order to continue. For any error in the client's request, you should be returning 400; for problems from the remote server (such as 404's), you should return that error.

Request/Response Line length?

Q) What is the maximum length for a request or response line that I have to support?
A) The RFC does not specify a maximum value for these elements; you should not simply set a fixed value and then fail for larger requests. At the same time, you don't want to grow the buffer to an unbounded size; doing so sets up your proxy for an easy denial-of-service attack. Instead, you should start with your buffer at a small size, and then grow the buffer to some reasonable limit- say 8-16 KB. Document your decision in your assignment's README file. Take a look at the realloc man page for information on dynamically growing a buffer.