Experiment 6.3 FAQ

Experiment 6.3: Frequently Asked Questions


  1. Should there be a configuration file of supported Content-types? Our server only supports text/html and test/plain right now. Should we support the standard ones like image/gif, image/jpg, etc?
  2. How do we determine things like the virtual root directory.
  3. If a "../../" occurs in the URL, should we allow the user to read files above the virtual root directory on the file system?
  4. Is there any reason you can think of why a .gif image would fail to load properly when sent by my http server? HTML pages come up correctly, but when I try to load a gif, it comes up in Netscape as a broken picture. When I manually telnet to my port and request a gif, it appears to be sending correctly, i.e. HTTP header, followed by a blank line, and then a bunch of control characters.
  5. My web server works with one browser but not with another? How can that happen?
  6. How do I call C functions in a C++ program?
  7. How do I put an int into a string?


Should there be a configuration file of supported Content-types? Our server only supports text/html and test/plain right now. Should we support the standard ones like image/gif, image/jpg, etc?

Support at least the necessary ones to load the example documents in htdocs. They are "text/html" for html files, "text/plain" for plain text, and "image/gif" for gif files. You will change the Content-type depending of the suffix of the file. For example, if the requested file ends with .html or .htm, then the Content-type will be "text/html". If it ends with ".gif, then the content type is "image/gif" . You don't need a configuration file for that. You can hardwire in your program the types specified above. It is up to you if you want to implement a configuration file.

Back to the top


Should there be a configuration file of supported Content-types? Our server only supports text/html and test/plain right now. Should we support the standard ones like image/gif, image/jpg, etc?

Support at least the necessary ones to load the example documents in htdocs. They are "text/html" for html files, "text/plain" for plain text, and "image/gif" for gif files. You will change the Content-type depending of the suffix of the file. For example, if the requested file ends with .html or .htm, then the Content-type will be "text/html". If it ends with ".gif, then the content type is "image/gif" . You don't need a configuration file for that. You can hardwire in your program the types specified above. It is up to you if you want to implement a configuration file.

Back to the top


How do we determine things like the virtual root directory.

The virtual root directory is the directory the server looks up for documents. By default the virtual root directory of your server will be the current directory where you execute your server. It is up to you if you want to implement passing a different root directory as argument.

Back to the top


If a "../../" occurs in the URL, should we allow the user to read files above the virtual root directory on the file system?

Make sure that the URL's do not go above the virtual root directory. This is the least security mechanism that your http server will have. If a URL tries to read above the virtual root return an error.

Back to the top


Is there any reason you can think of why a .gif image would fail to load properly when sent by my http server? HTML pages come up correctly, but when I try to load a gif, it comes up in Netscape as a broken picture. When I manually telnet to my port and request a gif, it appears to be sending correctly, i.e. HTTP header, followed by a blank line, and then a bunch of control characters.

Make sure to use "\015\012" instead of "\n" for the sequence. Make sure to use two sequences to separate the http header and the doument (or gif). That is the way the browser knows where the document starts.

Back to the top


My web server works with one browser but not with another? How can that happen?

(Thanks to Chris Wieringa) Any webserver that sent the Content-type for images worked fine on both common browsers, but those that did not do so broke down in one of the browsers.

Back to the top


How do I call C functions in a C++ program?

To include "C" functions in your C++ program you have to declare them as:

	 extern "C" 

For example type in your C++ program at the beginning.
 extern "C" int passiveTCP(const char *service, int qlen);
 extern "C" int errexit(const char *format, ...);


How do I put an int into a string?

You can use "sprintf()" to convert integers to string and to format the output. int sprintf(char *s, const char *format, /* args */ ... ); sprintf works like printf, however instead of sending the output to stdout, it sends it to the string "s" in the first argument. Make sure that "s" has enough space to store the output of sprintf.

Back to the top