1 / 10

CGI

CGI. CS422 Dick Steflik. Common Gateway Interface. "Old School" Basis for all of the current ways of making Web Apps Php ASP JSP Java Servlets. CGI. Commonly used languages PERL Python Ruby. CGI.

taya
Download Presentation

CGI

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. CGI CS422 Dick Steflik

  2. Common Gateway Interface • "Old School" • Basis for all of the current ways of making Web Apps • Php • ASP • JSP • Java Servlets

  3. CGI • Commonly used languages • PERL • Python • Ruby

  4. CGI • Provides a mechanism for a browser to request a web server to run a local program that will provide the body of an HTTP response packet • The request is in the form of an HTTP request packet and can be a GET or POST

  5. Environment Variables • CGI specifies a set of Environment Variables that are created from a combination of: • the servers runtime environment • information from the header of the browser's request packet

  6. COMSPEC="C:\Windows\system32\cmd.exe" DOCUMENT_ROOT="C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs" GATEWAY_INTERFACE="CGI/1.1" HOME="/home/SYSTEM" HTTP_ACCEPT="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" HTTP_ACCEPT_CHARSET="ISO-8859-1,utf-8;q=0.7,*;q=0.7" HTTP_ACCEPT_ENCODING="gzip, deflate" HTTP_ACCEPT_LANGUAGE="en-us,en;q=0.5" HTTP_CONNECTION="keep-alive" HTTP_HOST="example.com" HTTP_USER_AGENT="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0" PATH="/home/SYSTEM/bin:/bin:/cygdrive/c/progra~2/php:/cygdrive/c/windows/system32:..." PATHEXT=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" PATH_INFO="/foo/bar" PATH_TRANSLATED="C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\foo\bar" QUERY_STRING="var1=value1&var2=with%20percent%20encoding" REMOTE_ADDR="127.0.0.1" REMOTE_PORT="63555" REQUEST_METHOD="GET" REQUEST_URI="/cgi-bin/printenv.pl/foo/bar?var1=value1&var2=with%20percent%20encoding" SCRIPT_FILENAME="C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/printenv.pl" SCRIPT_NAME="/cgi-bin/printenv.pl" SERVER_ADDR="127.0.0.1" SERVER_ADMIN="(server admin's email address)" SERVER_NAME="127.0.0.1" SERVER_PORT="80" SERVER_PROTOCOL="HTTP/1.1" SERVER_SIGNATURE="" SERVER_SOFTWARE="Apache/2.2.19 (Win32) PHP/5.2.17" SYSTEMROOT="C:\Windows" TERM="cygwin" WINDIR="C:\Windows"

  7. timeline • user clicks "Submit" on web page • Browser builds an HTTP request packet • HTTP method is from <form> tag method attribute • if method is GET data is added on to URL as Query_String • if method is POST data (name value pairs) are put into the request packet body as URL encoded data • CGI is from <form> action attribute) • HTTP_User_Agent is set by the browser • TCP connection is made to port 80 on server from a random high numbered port on the client and request packet is sent to server • Server blocks port 80 and transfers to a random high numbered port to process the request packet then unblocks port 80 • The server processes the request

  8. timeline (cont.) • server processing • packet is received • body goes to SYSIN • info is taken from the request header and moved into environment variables • if HTTP method is GET • is the requested resource a CGI • then run the CGI • get data from QUERY_STRING • build the response packet (set Content-type to text/html) • else retrieve the resource • if HTTP method is POST • run the CGI • read the data from SYSIN • build the response packet (set Content-type to text/html) • send the response packet • close the TCP connection

  9. name/value data • depending on the CGI language the name/value data is handeled differently • python name/values are consumed from SYSIN or QUERY_STRING and moved to a Python dictionary called FielsStorage() and can be retrieved via getvalue() • perl usually moves the name/value pairs from SYSIN or QUERY_STRING into a buffer and then splits them into an associative array • java usually has library support to put it into a hash table

  10. State in a Stateless Environment • program state in the HTTP stateless environment must be maintained by coordinating the browser and the CGI • one way is by hiding state variables in the HTML form by using hidden fields modified by the CGI to reflect state • <input name= something type=hidden /> • another way is by using cookies in the response header • or a combination of the two

More Related