u413-284-si / webserv

This project is about setting up a http web server, providing a static website.
MIT License
0 stars 0 forks source link

response_building: handle CGI requests #18

Open u413-284-si opened 2 months ago

u413-284-si commented 2 months ago

The web server receives a request just like any other, but notes that this URL does not map to a flat file, but instead somehow to a scripting area.

Example: GET /cgi-bin/script.cgi?name=value HTTP/1.1

(All the CGI Programs to be executed by the HTTP server are kept in a pre-configured directory. This directory is called CGI directory and by convention it is named as /var/www/cgi-bin. By convention CGI files will have extension as .cgi, though they are a PERL, Shell, C or C++ executable.)

The server then starts the script, feeding it all the information contained in the request headers and URL. The script then runs and produces as its output the HTML and HTTP headers to be returned to the client, which the server takes care of.

Subtasks:

  1. REQUEST_METHOD: The method used in the request (GET, POST, etc.).
  2. QUERY_STRING: The query string part of the URL (for GET requests).
  3. CONTENT_TYPE: The MIME type of the request body (for POST requests).
  4. CONTENT_LENGTH: The length of the request body (for POST requests).
  5. SCRIPT_NAME: The path to the script being executed.
  6. PATH_INFO: Extra path information.
  7. REMOTE_ADDR: The IP address of the client.
  8. HTTP_USER_AGENT: The user agent string.