1 / 19

How does the server format the information it gives to the appln program?

How does the server format the information it gives to the appln program?. As environment variables and in standard input. Example. Suppose you were to send the request below from interzone interzone.ucc.ie> telnet student.cs.ucc.ie 80 Trying 143.239.211.125...

xanti
Download Presentation

How does the server format the information it gives to the appln program?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How does the server format the information it gives to the appln program? As environment variables and in standard input

  2. Example • Suppose you were to send the request below from interzone interzone.ucc.ie> telnet student.cs.ucc.ie 80 Trying 143.239.211.125... Connected to student.cs.ucc.ie. Escape character is '^]'. GET /cs1064/jabowen/cgi-bin/respond.cgi/extra/path/info.txt?city=cork&man=fred HTTP/1.1 Host: student.cs.ucc.ie • The application program, respond.cgi, would receive the environment variables shown on the next slide • On the subsequent slides, we will consider where the values of these environment variables come from

  3. QUERY_STRING city=cork&man=fred SERVER_ADDR 143.239.211.125 SERVER_PROTOCOL HTTP/1.1 PATH_TRANSLATED /usr/local/www/docs/extra/path/info.txt REMOTE_PORT 3719 GATEWAY_INTERFACE CGI/1.1 HTTP_HOST student.cs.ucc.ie PATH_INFO /extra/path/info.txt SERVER_SOFTWARE Apache/1.3.14 (Unix) PHP/4.0.3pl1 SERVER_ADMIN webmaster@cs.ucc.ie REMOTE_ADDR 143.239.1.134 SCRIPT_NAME /cs1064/jabowen/cgi-bin/respond.cgi SERVER_NAME student.cs.ucc.ie DOCUMENT_ROOT /usr/local/www/docs REQUEST_URI /cs1064/jabowen/cgi bin/respond.cgi/extra/path/info.txt?city=cork&man=fred SCRIPT_FILENAME /usr/local/www/docs/cs1064/jabowen/cgi-bin/respond.cgi REQUEST_METHOD GET PATH /bin:/usr/bin:. SERVER_PORT 80

  4. How does the server pass the information it received in the HTTP request line? • Remember that the request line contains a request method, a URI and a HTTP version • The request method is passed to the appln program in an environment variable called REQUEST_METHOD • The request-URI is passed to the appln program in an environment variable called REQUEST_URI • The HTTP version is passed to the appln program in an environment variable called SERVER_PROTOCOL

  5. Cs 4320 got here on 21 jan 2005

  6. How does the server pass the information it received in HTTP headers? • This information is sent to the application program through environment variables • With two exceptions (see later), the names of these variables are derived from the names of the HTTP headers, by preceding each header name with HTTP_ • Examples are on the next slide

  7. Examples • For example, consider the request header Host: student.cs.ucc.ie This is relayed by the server onto the appln program as the following environment variable and value HTTP_HOST student.cs.ucc.ie • Even non-standard headers are treated the same way. • For example, suppose that, when a human telnets to a HTTP server, he sends the non-standard header Grocery-Order: rashers This is relayed to the appln program as HTTP_GROCERY_ORDER rashers • Note that hyphens in HTTP headers are converted to underscores in the names of environment variables

  8. How does the server pass the HTTP message body (if any)? • Remember that not all HTTP request messages contain message bodies • But if a request message does have a body, this is passed to the appln program through standard input • For example, a request which uses the POST method does have a message body, containing data captured in a HTML form • the form data are passed to the application program in standard input • The environment variableCONTENT_LENGTHspecifies the number of bytes of data the message body in standard input contains

  9. How does the server pass the message body (contd.) • For requests which have message bodies (such as POST and PUT requests), the type of the data in the message body is given in the environment variable CONTENT_TYPE • Thus, CONTENT_TYPE and CONTENT_LENGTH are exceptions to the rule that HTTP header values are passed in environment variables in whose names the header names are preceded by HTTP_

  10. What other information does the server pass to the appln program? The HTTP server demon uses the following environment variables to send other information (besides the content of the HTTP request) to the application program: • SERVER_SOFTWARE Name and version of HTTP server software • SERVER_NAME and/or SERVER_ADDR The hostname and/or IP address of the server machine. • SERVER_PORT The TCP/IP port being used by the HTTP server demon. • SERVER_ADMIN Email address of the server’s system administrator, if available

  11. Other information passed by server (contd.) • GATEWAY_INTERFACE Version of CGI protocol in use. Format: CGI/revision • REMOTE_ADDR IP address of the client machine • REMOTE_HOST Domain name of the client machine, if available. • REMOTE_PORT Port number on the client machine which sent the request, if available.

  12. Other information passed by server (contd.) • DOCUMENT_ROOT This environment variables is not always passed by servers but, when it is used, it contains the path, within the directory structure on the server machine, to the top of the sub-tree from which the HTTP demon serves documents. For example, an application program running on student.cs.ucc.ie would receive DOCUMENT_ROOT /usr/local/www/docs because all web documents on this machine are stored in this branch of the directory tree. For example, the file whose URL is http://student.cs.ucc.ie/cs1064/jabowen/welcome.htm is actually stored at /usr/local/www/docs/cs1064/jabowen/welcome.htm

  13. Other information passed by server (contd.) • PATH_INFO Contains any additional “path” info which was appended, in the Request-URI, to the name of the application program • Example Consider the following HTTP request GET /cs1064/jabowen/cgi-bin/respond.cgi/extra/path/info.txt?city=cork&man=fred HTTP/1.1 Host: student.cs.ucc.ie The server recognizes that the application program is respond.cgi so it passes the string /extra/path/info.txt in the environment variable PATH_INFO PATH_INFO /extra/path/info.txt

  14. Other information passed by server (contd.) • The information which appears in PATH_INFO also appears in another variable, called PATH_TRANSLATED • PATH_TRANSLATED contains the complete path from the root directory of the machine • For example, if DOCUMENT_ROOT /usr/local/www/docs and PATH_INFO /extra/path/info.txt then PATH_TRANSLATED /usr/local/www/docs/extra/path/info.txt

  15. Other information passed by server (contd.) • QUERY_STRING This environment variable is used to pass the information which follows the ? in the Request-URI • Example HTTP Request GET /cs1064/jabowen/cgi-bin/respond.cgi/extra/path/info.txt?city=cork&man=fred HTTP/1.1 Host: student.cs.ucc.ie The server sets QUERY_STRING as follows: QUERY_STRING city=cork&man=fred

  16. Other information passed by server (contd.) • SCRIPT_FILENAME Full path and name, relative to the root directory of the server machine, of the CGI script • SCRIPT_NAME Path and name, relative to the DOCUMENT_ROOT of the server demon, of the CGI script

  17. Other information passed by server (contd.) • AUTH_TYPE If the server supports user authentication, and the script is protected, this is the protocol-specific authentication method used to validate the user. • REMOTE_USER If the server supports user authentication, and the script is protected, this is the username they have authenticated as. • REMOTE_IDENT If the HTTP server supports RFC 931 identification, then this variable will be set to the remote user name retrieved from the server. Usage of this variable should be limited to logging only.

  18. Other information passed by server (contd.) • Any other environment variables that exist in the environment of the “user” which is running the server • Example: PATH /bin:/usr/bin:.

  19. Cs 4320 got here on 10 feb 2004

More Related