1 / 16

Common Gateway Interface

Common Gateway Interface. (CGI). CGI is a protocol:. CGI is not a programming language CGI is a protocol for the exchange of information between between an HTTPD demon (server program) and application programs which run on the same machine as the HTTP server. When is CGI used?.

kata
Télécharger la présentation

Common Gateway Interface

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. Common Gateway Interface (CGI)

  2. CGI is a protocol: • CGI is not a programming language • CGI is a protocol for the exchange of information between between • an HTTPD demon (server program) and • application programs which run on the same machine as the HTTP server

  3. When is CGI used? • When a HTTPD server receives a request for a resource, it can either • deliver the resource to the requesting client, or • treat the resource as a program which will generate some output that is to be sent to the requesting client • Servers can use different criteria to decide whether a requested file in its directory structure is to be delivered or executed • the decision could be based on the directory in which the file is located • the decision could be based on the type of the file, as reflected in its name extension

  4. A typical approach: • Most types of file are served up to the requesting client: html, jpg, gif, wav • Files whose names have the extension .cgi are treated as programs to be executed, programs whose output is to be served up to the requesting client

  5. This is when CGI is used: • When a HTTP server has decided that a requested resource is to be treated as program, • it uses CGI to exchange information with the program

  6. What channels are used? • The HTTP server demon sends information to an application program using • standard input • environment variables • The application program sends information to the HTTP server demon using • standard output

  7. What languages can appln programs be written in? • They can be written in ANY language provided the language is able to access the communication channels used by the CGI protocol • standard input • standard output • environment variables

  8. What does the CGI protocol specify? • It specifies • the information that the HTTP demon should provide to the application program • through environment variables • through standard input • the information that the application should provide to the demon through standard output • the way in which all this information should be encoded and decoded

  9. What information should the HTTP server demon provide to the application program? • The server should give the appln program • information about the client, such as • the IP address or domain name of the client machine, etc • all the information it received in the HTTP request message: • the request method, URI and HTTP version used in the request line • all the information in the HTTP message headers (if any) that followed the request line • all the information in the HTTP message body (if any) that followed the blank line after the last header • information about the server itself, such as • the version of CGI it is using to the talk to the appln program; • the IP address or domain name of the server machine • the TCP/IP port which is being used by the HTTP demon

  10. Cs 4320 got here on 6/feb/2004

  11. What information should the appln program provide to the HTTP server demon? • The appln program gives to the HTTP server demon whatever information it wants to have sent, by the HTTP server demon, to the client • This means that the appln program can determine • the status line of the response message • the headers used in the response message • the body (if any) in the response message

  12. Status line • Usually, an appln program says nothing to the HTTP server about the status code (and associated natural language phrase) that should be sent in the status line of the HTTP response message to the client • in this case, the HTTP server will select the code and phrase itself • However, an appln program can choose the status code and phrase itself • Indeed, as we will see later, since the set of HTTP server codes is extensible, • we can write application programs which choose non-standard codes

  13. Cs 4320 got here on 18 jan 2005

  14. Message Headers • Most appln programs are willing to let the HTTP server select what headers to send to the client • Usually, however, an appln program gives at least one header to the server • typically, either a Content-Type: or a Location: header • An appln program can insist that the HTTP server should not add any more headers to the message, extra to those that the appln program has given to the server • Usually, however, the appln program lets the server parse the headers and decide to send additional headers which it thinks are necessary

  15. Message body • The application program has sole control on what body, if any, is sent in the response message

More Related