SDSU CS 596: Client Server Programming
HTTP

[To Lecture Notes Index]
San Diego State University -- This page last updated February 28, 1995
----------

Contents of HTTP Lecture

  1. URL
  2. HTML
  3. HTTP
    1. HTTP Message Format
    2. Client Request
      1. Request Methods
      2. Header Fields
      3. General Message Header Fields
      4. Request-Header
    3. Server Response
      1. Response-Header
    4. Object Header Fields
    5. Negotiation Algorithm

Reference

Hypertext Transfer Protocol - HTTP/1.0, Berners-Lee, Fielding, Nielson;
URL:http://www.ics.uci.edu/pub/ietf/http/draft-fielding-http-spec-01.txt

Uniform Resource Locators (URL), Berners-Lee, Masinter, McCahill; RFC 1738


URL

URL = Uniform Resource Locator

gopher://gopher.yoyodyne.com/
news:rec.gardening
http://www.yoyodyne.com/pub/foobar.html
http://www.yoyodyne.com/pub/foobar.html?roger

Common Internet Scheme Syntax

URL schemes that involve the direct use of an IP-based protocol to a specified host on the Internet use a common syntax for the scheme-specific data:
//<user>:<password>@<host>:<port>/<url-path>

gopher

gopher://<host>:<port>/<gopher-path>
http

http://<host>:<port>/<path>?<searchpart>
mail

mailto:<rfc822-addr-spec>
news

news:<newsgroup-name>
news:<message-id>

prospero

prospero://<host>:<port>/<hsoname><field>=<value&t;
telnet

telnet://[<user>:<password>]@<host>[:<port>/]
wais

wais://<host>:<port>/<database>
wais://<host>:<port>/<database>?<search>
wais://<host>:<port>/<database>/<wtype>/<wpath>

HTML

WWW

World Wide Web (or Web, for short)
SGML
Standard Generalized Markup Language
this is a standard for describing markup languages

DTD

Document Type Definition
this is a specific markup language, written using SGML
HTML

HyperText Markup Language
HTML is a SGML DTD.
HTML uses markup tags to tell the Web browser how to display the text

HTML Example
HTML Source

<TITLE>The simplest HTML example</TITLE>

<H1>This is a level-one heading</H1>

Welcome to the world of HTML.

This is one paragraph.<P>

And this is a second.<P>

As Displayed by Web browser

This is a level one heading

Welcome to the world of HTML. This is one paragraph.

And this is a second.


HTML Tags

HTML is not case sensitive

<title> is equivalent to <TITLE> or <TiTlE>.

<TITLE>My Title</TITLE>

<Hy>Text of heading </Hy >

y = 1 | 2 | ... | 6

Paragraphs

Paragraphs have to be indicated by <P>

<CENTER> center </CENTER>

<B> bold text </B>

<CENTER><B> center </B></CENTER>

<I> italic text </I>

<TT> typewriter text, </TT>

<CITE> for titles of books, films, etc. </CITE>

<CODE> for snippets of computer code.</CODE>

<STRONG> for strong emphasis</STRONG>

<HR> tag produces a horizontal line


Links
Simple

In document Foo.html create a link to document fancy.html

<a href="fancy.html#MyLink">Click On Me</a>

In document fancy.html indicate the link by

<a name="MyLink">You end up here</a>

General Link

Link to a document on another machine

<A HREF="http://www.racal.com/rfc.html">
Internet RFCs
</A>

Link to an image

<A HREF="http://www.racal.com/rfc.gif">
Great Picture of Internet RFCs
</A>


Type of Files for Links

<A HREF="http://host/fileName.extensions">

Great Stuff

</A>

File Type	Extension 
Plain text 	.txt 
HTML document 	.html 
GIF image 	.gif 
TIFF image 	.tiff 
XBM bitmap image 	.xbm 
JPEG image 	.jpg or .jpeg 
PostScript file 	.ps 
AIFF sound 	.aiff 
AU sound 	.au 
QuickTime movie 	.mov 
MPEG movie 	.mpeg or .mpg 

Sample Document
<!DOCTYPE HTML SYSTEM "html.dtd">
<HTML>
<HEAD><TITLE>
CS 596: Gopher Protocol
</TITLE></HEAD>

<BODY>
<H2>
<IMG SRC="http://www.sdsu.edu/graphics/sdsu_logo_3.gif" ALT="SDSU" HSPACE=20>
CS 596: Client Server Programming<br>
<center>
Gopher Protocol
</center>
</H2>

<CENTER>
<A HREF="../index.html">[To Lecture Notes Index]</a><br>
San Diego State University<I> -- This page last updated February 20, 1995</I>
</CENTER>

<IMG SRC="http://www.sdsu.edu/graphics/divider_red.gif" ALT="----------">
<P>
<center><h3>
Contents of Gopher Protocol Lecture
</h3></center>
</body>
</html>

HTTP

Hypertext Transfer Protocol

stateless, object-oriented protocol

The typing and negotiation of data representation, allows systems to be built independently of the data being transferred

Assigned port 80

Basic Server-Client Interaction

Client: Open connection

Server: Accept/Reject connection

Client: Send request

Server: Send response to request

Connection closed


Some Terms for this Lecture only

origin server

The server on which a given resource resides or is to be created.

proxy

An intermediary program which acts as both a server and a client for the purpose of forwarding requests. Proxies are often used to act as a portal through a network firewall.
gateway
A proxy which services HTTP requests by translation into protocols other than HTTP.

Augmented BNF

"literal"

Quotation marks surround literal text. Unless stated otherwise, the text is case-insensitive.

rule1 | rule2

Elements separated by a bar ("|") are alternatives,

(rule1 rule2)

Elements enclosed in parentheses are treated as a single element.
(elem (foo | bar) elem) =
elem foo elem |
elem bar elem".

*rule

"*" preceding an element indicates repetition

<n>*<m>element

at least <n> and at most <m> occurrences of element
"1*3element" allows one or two or three elements
Default values n =0 and m = infinity

[rule]

Square brackets enclose optional elements;

<n>(element)

exactly <n> occurrences of (element)
2DIGIT is a 2-digit number

<n>#<m>element

at least <n> and at most <m> elements, each separated by one or more commas (",") and optional linear white space (LWS).

; comment

A semi-colon, set off some distance to the right of rule text, starts a comment that continues to the end of line.

OCTET = <any 8-bit character>

CHAR = <any US-ASCII character (octets 0 - 127)>

UPALPHA = <uppercase letter "A".."Z">

LOALPHA = <lowercase letter "a".."z">

ALPHA = UPALPHA | LOALPHA

DIGIT = <"0".."9">

CTL = <control character (octets 0 - 31) and DEL>

CR = <carriage return (13)>

LF = <linefeed (10)>

SP = <space (32)>

HTAB = <horizontal-tab (9)>

<"> = <double-quote mark>

LWS = [CRLF] ( SP | HTAB )


HTTP Message Format

HTTP-message   =	Simple-Request	; 	HTTP/0.9 messages
	| Simple-Response
	| Full-Request	; 	HTTP/1.0 messages
	| Full-Response


Full-Request   =	Request-Line 
	*General-Header 
	*Request-Header 
	*Object-Header    
	CRLF
	[ Object-Body ]


Full-Response  = 	Status-Line      
	*General-Header  
	*Response-Header
	*Object-Header      
	CRLF
	[ Object-Body ]


HTTP-header	= field-name ":" [ field-value ] CRLF

Object-Body	= *OCTET


Client Request

Request    = Simple-Request | Full-Request

Simple-Request = "GET" SP URI CRLF

Simple-Request Example

telnet: saturn 8080

Server: accepts connection

Telnet: GET /cs/cs596_3/ <CRLF>

Server:

<!DOCTYPE HTML SYSTEM "html.dtd">
<HTML><HEAD><TITLE>CS-596: Client Server Programming</TITLE></HEAD>
<BODY><H2><IMG SRC="http://www.sdsu.edu/graphics/sdsu_logo_3.gif" ALT="SDSU" HSP
ACE=20>
CS-596: Client Server Programming
</H2>
<CENTER>

etc.


Full-Request
Request    = Simple-Request | Full-Request

Full-Request   =	Request-Line 
	*General-Header 
	*Request-Header 
	*Object-Header    
	CRLF
	[ Object-Body ]

Request-Line = Method SP URI SP HTTP-Version CRLF

Telnet: saturn 8080

Server: accepts connection

Telnet: GET /cs/cs596_3/ HTTP/1.0 <CRLF>

Telnet: <CRLF>

Server:

HTTP/1.0 200 Document follows
MIME-Version: 1.0
Server: CERN/3.0
Date: Wednesday, 22-Feb-95 19:48:55 GMT
Content-Type: text/html
Content-Length: 1831
Last-Modified: Wednesday, 15-Feb-95 18:28:05 GMT
<!DOCTYPE HTML SYSTEM "html.dtd">
<HTML><HEAD><TITLE>CS-596: Client Server Programming</TITLE></HEAD>

Request Methods

Method         = "GET" | "HEAD" | "PUT" | "POST"
	| "DELETE" | "LINK" | "UNLINK"
	| extension-method

GET and HEAD must be supported by all HTTP/1.0 servers

Servers should return the Status-Code

"501 Not Implemented"

if the method is unknown.

GET

Retrieves whatever object is identified by the URI.

The URI can refer to a data-producing process, or a script

The produced data which shall be returned as the Object-Body

HEAD

Identical to GET except that the server must not return any Object-Body in the response

POST

Request that the origin server accept the object enclosed in the request as a new subordinate of the resource identified by the URI

Allows a uniform function to:

Annotation of existing documents;
Posting a message to a bulletin board topic, newsgroup, mailing list, or similar group of articles;
Providing a block of data (usually a form) to a data-handling process, or a script which can be run by such a process;
Extending a document during authorship

PUT

The enclosed Object in the request is to be stored under the supplied URI

DELETE

Requests that the server delete the resource identified by the given URI

LINK

Establishes one or more Link relationships between the existing resource identified by the URI and other existing resources

UNLINK

UNLINK method removes one or more Link relationships from the existing resource identified by the URI


Header Fields

HTTP-header	= field-name ":" [ field-value ] CRLF


field-name	= 1*<any CHAR, excluding CTLs, SP, and ":">


field-value 	 = *( field-content | comment | LWS )


field-content  = <the OCTETs making up the field-value
	and consisting of either *text or combinations
	of token, tspecials, and quoted-string>

Examples

Date: Wednesday, 22-Feb-95 19:48:55 GMT

Content-Type: text/html

Content-Length: 1831


General Message Header Fields

General-Header = Connection
	| Date
	| Forwarded
	| Mandatory
	| Message-ID
	| MIME-Version
Connection
Connection     = "Connection" ":" 1#connect-option

connect-option = token [ "=" word ]

Example: Connection: keep-alive

Date

Formats accepted

Preferred:

Sun, 06 Nov 1994 08:49:37 GMT
RFC 822, updated by RFC 1123
Others:

Sunday, 06-Nov-94 08:49:37 GMT
Sun Nov 6 08:49:37 1994
Forwarded

Used by proxies to indicate the intermediate steps between the user agent and the server

Forwarded      = "Forwarded" ":" "by" URI [ "(" product ")" ]
				[ "for" FQDN ]

FQDN           = <Fully-Qualified Domain Name>

Example:

Forwarded: by http://info.cern.ch:8000/ for ptsun00.cern.ch

Mandatory

The Mandatory header is used to indicate a list of other header field names which must be understood by the receiver

This header is used to alert the receiver that, unlike the default behavior, it cannot safely ignore the semantics of the listed field-names if they are not understood.

It is anticipated that the field names correspond to conditions that must be met by the receiver in order to abide by the sender's licensing, copyright, payment, or other fair-usage constraints.

Mandatory = "Mandatory" ":" 1#field-name

Message-ID

The Message-ID field in HTTP is identical to that used by Internet Mail and USENET messages

A single, unique identifier which can be used for identifying the message (not its contents) for "much longer" than the expected lifetime of that message.

Message-ID     = "Message-ID" ":" "<" addr-spec ">"
addr-spec      = unique-string "@" FQDN
unique-string  = <1*CHAR, not including whitespace, "@", or ">">

Message-ID: <9411151630.4256@info.cern.ch>

MIME-Version

HTTP/1.0 messages may include a single MIME-Version header field to indicate what version of the MIME protocol was used to construct the message.

Unfortunately, current versions of HTTP/1.0 clients and servers use this field indiscriminately, and thus receivers must not take it for granted that the message is indeed in full compliance with MIME.

MIME-Version   = "MIME-Version" ":" 1*DIGIT "." 1*DIGIT

Request-Header

Request    = Simple-Request | Full-Request

Full-Request   =	Request-Line 
	*General-Header 
	*Request-Header 
	*Object-Header    
	CRLF
	[ Object-Body ]

Request-Header = User-Agent
	| If-Modified-Since
	| Pragma
	| Authorization
	| Proxy-Authorization
	| Referer
	| From
	| Accept
	| Accept-Encoding
	| Accept-Language

Server Response

Response = Simple-Response | Full-Response

Simple-Response= [Object-Body]

Full-Response  = Status-Line              
	*General-Header         
	*Response-Header      
	*Object-Header      
	CRLF
	[ Object-Body ]        

Simple response is sent only in response to HTTP/0.9 simple request

Sample Full-response

HTTP/1.0 200 Document follows
MIME-Version: 1.0
Server: CERN/3.0
Date: Wednesday, 22-Feb-95 19:48:55 GMT
Content-Type: text/html
Content-Length: 1831
Last-Modified: Wednesday, 15-Feb-95 18:28:05 GMT

Status-Line

Status-Line = HTTP-Version SP 
	Status-Code SP Reason-Phrase CRLF

Example:

HTTP/1.0 200 Document follows

Status-Code = 3DIGIT

Reason-Phrase = token *( SP token )

Current Status Codes

1xx: Not used, but reserved for future use

2xx: Success - The requested action was successfully received and understood

3xx: Redirection - Further action must be taken in order to complete the request

4xx: Client Error - The request contains bad syntax or is inherently impossible to fulfill

5xx: Server Error - The server could not fulfill the request


Response-Header

Full-Response  = Status-Line              
	*General-Header         
	*Response-Header      
	*Object-Header      
	CRLF
	[ Object-Body ]        

Response-Header= Server
	| WWW-Authenticate
	| Proxy-Authenticate
	| Retry-After

Unknown header fields should be considered Object-Header fields.


Object Header Fields

Object-Header  = Allow
	| Content-Length
	| Content-Type
	| Content-Encoding
	| Content-Transfer-Encoding
	| Content-Language
	| Expires
	| Last-Modified
	| URI-header
	| Location
	| Version
	| Derived-From
	| Title
	| Link
	| extension-header
extension-header=HTTP-header

Allow

Set of methods allowed by the object


Negotiation Algorithm

q (quality)

Level of degradation when rendering in the client.
q element of E[0,1], the default value is q=1

qs (quality server)

q factor for the server in when it performs media-type conversions
Default value is qs=1

mxb

The maximum number of bytes accepted by the client
Default value is mxb=undefined (i.e. infinity)

bs

The actual number of bytes

			{ if mxb=undefined,	then (qs * q) }
Q(q,qs,mxb,bs) = 	{ if mxb >= bs,	then (qs * q) }
			{ if mxb <  bs,	then 0        }

The maximum of the Q function represents the preferred media-type

Examples of Using Accept
Telnet:	saturn 8080
Server:	accepts connection
Telnet:	GET /cs/cs596_3/ HTTP/1.0	
	Accept: audio/*; q=0.2, 
		audio/basic

Accept: text/plain; q=0.5, 
	text/html,
	text/x-dvi; q=0.8; mxb=100000, 
	text/x-c