A browser submits a form with method POST to a CGI script written in C. Put the stages of handling this single request in the order they occur, from the browser's request to the reply it receives.
1.
The browser sends an HTTP request for the script URL with the form data in its body.
2.
The web server sets environment variables such as REQUEST_METHOD and CONTENT_LENGTH for a new process.
3.
The server adds the HTTP status line and forwards the response to the browser.
4.
The program reads exactly CONTENT_LENGTH bytes from standard input and decodes the form fields.
5.
The program writes a Content-Type header, a blank line and the response body to standard output.
6.
The server starts the CGI program and connects the request body to its standard input.
Unlock full course notes by signing up
Decoding a query-string value and sizing its buffer
A CGI program receives a GET request whose QUERY_STRING environment variable is set to
msg=Hi%21+5%2B3%3D8
Consider only the value of msg, the text after msg=. Find the length of the encoded value in bytes, the number of %XX escapes it contains, the length of the decoded value in bytes, and the smallest char array size in bytes that holds the decoded value as a C string. Give each as a whole number.
Meta-variables and stdin bytes for three requests
A web server receives the three HTTP requests below. Each request is mapped to a C program in /cgi-bin/. For each request, enter the values of REQUEST_METHOD and QUERY_STRING exactly as the server sets them. Also enter the number of bytes the program should read from standard input. Bodies are shown exactly as transmitted, with no trailing newline.
Cost of starting a process for every CGI request
A small server runs a C order-lookup program through CGI on a machine with 4 CPU cores. Profiling shows two costs for each request. Creating the process and starting the program takes 12 ms of CPU time; this covers fork, exec, dynamic linking and opening a database connection. Handling the request itself takes a further 3 ms of CPU time. Assume the work is CPU-bound, requests spread evenly over the cores, and nothing else runs on the machine.
Find:
the CPU time per request, in ms, as a whole number;
Finding the faults in a CGI POST handler
A student writes this CGI program to echo a POST request body back to the browser. The standard headers are included and the program compiles without warnings.
Which of the following statements about this program are true? Select all that apply.