![]() |
Web Conference 2004Writing Perl/CGI Scripts for ITS/ASET Web servicesMore on HTTP |
| <- Back - More on Perl | | | Up | | | Speaking CGI - Next -> |
Here is a crash course in HTTP.
HTTP sessions involve a request sent by the browser, followed by a response from the server. Some HTTP sessions may contain multiple pairs of requests and responses. The HTTP request and response each have an associated version of HTTP, which may vary if the request was at least version 1.0.
When a browser wants to visit a Web page, it makes a Transmission Control Protocol (TCP) connection to the Web server and then submits a request in HTTP. It looks like the following:
| Browser --HTTP==> Web Server |
|---|
GET /users/j/c/jcd/useful/webcon/2004/helloworld.cgi HTTP/1.0 |
The first word is the method, which in this case is GET. The second part is the Uniform Resource Indicator (URI) or Uniform Resource Locator (URL), the name of the file or script desired as local to the server. The last part indicates the version of HTTP the browser is speaking. In this case, it is version 1.0. Notice there is a blank line. This indicates the end of the HTTP headers. If the browser wanted to pass additional information, such as last page visited (Referer:), cookies (Cookie:) or authentication information (Authorization:) it would do so in successive lines.
When the browser has finished the request, the server replies. The version of HTTP the server uses may be different than the version the browser used if it is at least 1.0. A response may look like:
| Browser <==HTTP-- Web Server |
|---|
HTTP/1.1 200 OK Date: Sun, 13 Jun 2004 19:47:48 GMT Server: Apache/1.3.12 (Unix) mod_ssl/2.6.2 OpenSSL/0.9.5a Connection: close Content-Type: text/html <html> <body> <p>Hello world! Here is some HTML inside a basic CGI script</p> </body> </html> |
The first line indicates the version of HTTP, which is 1.1 in this case, followed by the status code, followed by a human readable comment. Computers usually ignore the last part and instead rely on the number. The status code 200 means "OK" or "everything was fine with the request and here is the document you asked for." Successive lines are the rest of the HTTP headers, indicating the current date according to the server, the server software, the status of the connection (closing, or left open waiting for further requests) and a content-type (or MIME type) of the document being served. The exact headers sent may vary depending on the server software, its configuration, and the type and status of the URI requested.
There is a blank line which indicates the end of the headers. Following this is the document in its entirety.
Versions of HTTP
HTTP/0.9 - The oldest version still supported today. Any request without the version number is implied 0.9. Replies to 0.9 requests must also be 0.9 and do not include a header. No futher information (headers) may be supplied with a 0.9 request.
HTTP/1.0 - A version that supports nearly all HTTP features of today. Requests may be as simple as 0.9, or may be as full as 1.1. It has the ability to supply further lines of information such as Referer, Cookie, Authorization, Content-Type, Content-Length (for use with request bodies, eg POST data).
HTTP/1.1 - The latest version of HTTP. It looks nearly identical to 1.0 except it has required elements. A 1.1 request must also include a Host: header indicating the domain name corresponding to the request. 1.1 requests also imply the Connection: is set to keep-alive, rather than close, which means the server will leave the TCP connection open for successive requests by the browser, until the browser indicates it is finished with the connection.
More about HTTP/1.1 from the standards document, Request For Comments (RFC) # 2616 - Hypertext Transfer Protocol - HTTP/1.1, or RFC 2145 - Use and Interpretation of HTTP Version Numbers.
| <- Back - More on Perl | | | Up | | | Speaking CGI - Next -> |
If you have any questions, feel free to ask me - mailto:jcd@psu.edu
Content by: Jeff D'Angelo <jcd@psu.edu> © 2004
Last update on: Thursday, 17-Jun-2004 11:46:23 EDT