This preview shows page 1. Sign up to view the full content.
Unformatted text preview: e 12.47 handles one HTTP transaction. First, we read and parse the request line (lines 9-10). Notice that we are using the robust readline function from Figure 12.16 to read the request line. T INY only supports the GET method. If the client requests another method (such as POST), we send it an error message and return to the main routine (lines 11-15), which then closes the connection and awaits the next connection request. Otherwise, we read and (as we shall see) ignore any request headers (line 16). Next, we parse the URI into a ﬁlename and a possibly empty CGI argument string, and we set a ﬂag that indicates whether the request is for static or dynamic content (line 19). If the ﬁle does not exist on disk, we immediately send an error message to the client and return (lines 20-24). Finally, if the request is for static content (lines 26), we verify that the ﬁle is a regular ﬁle (i.e., not a directory ﬁle or a FIFO) and that we have read permission (line 27). If so, we serve the static content (line 32) to the client. Similarly, if the request is for dynamic content (line 34), we verify that the ﬁle is executable (line 35), and if so we go ahead and serve the dynamic content (line 40). 12.8. PUTTING IT TOGETHER: THE TINY WEB SERVER 655 code/net/tiny/tiny.c
1 2 3 4 5 6 7 8 9 10 11 12 13...
View Full Document
- Spring '10
- The American