38
1 6 HTTP Protocol Design and Description Web Protocols and Practice

HTTP Protocol Design and Description

  • Upload
    eliot

  • View
    36

  • Download
    0

Embed Size (px)

DESCRIPTION

6. HTTP Protocol Design and Description. Web Protocols and Practice. HTTP PROTOCOL DESIGN AND DESCRIPTION. Topics. Web Protocols and Practice. HTTP PROTOCOL DESIGN AND DESCRIPTION. Protocol Definition. Web Protocols and Practice. HTTP PROTOCOL DESIGN AND - PowerPoint PPT Presentation

Citation preview

Page 1: HTTP Protocol Design and                     Description

1

6

HTTP Protocol Design and Description

Web Protocols and Practice

Page 2: HTTP Protocol Design and                     Description

2

Topics

Web Protocols and Practice

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Protocol Definition Protocol Properties HTTP Headers HTTP Response Classes

Page 3: HTTP Protocol Design and                     Description

3

Protocol Definition

Web Protocols and Practice

A protocol is a language with a Grammar Syntactic structure Semantic rules

HTTP is A request-response protocol An application-level protocol

The HTTP protocol evolved along with the Web and URI and HTML. (Table 6.1)

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 4: HTTP Protocol Design and                     Description

4

Table 6.1. Historical timeline of HTTP-related documents

DateDocumentMar 1990

Jan 1992

Feb 1992

Dec 1992

Feb 1993

Mar 1993

Jun 1993

Oct 1993

Nov 1993

Mar 1994

May 1996

Jan 1997

Jun 1999

2001

CERN labs document proposing Web

HTTP/0.9 specification

W3 and WAIS/X.500

Proposal to add MIME to HTTP

UDI (Universal Document Identifier) for the Network

HTTP/1.0 first draft

HTML (1.0 Specification)

URL specification

HTTP/1.0 second draft

URI in WWW

HTTP/1.0 Informational, RFC 1945

HTTP/1.1 Proposed Standard, RFC 2068

HTTP/1.1 Draft Standard, RFC 2616

HTTP/1.1 Formal Standard

Web Protocols and Practice

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 5: HTTP Protocol Design and                     Description

5

Protocol Properties

Web Protocols and Practice

Global URI HTTP Request/Response Format Statelessness Resource Metadata HTTP Request Methods

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 6: HTTP Protocol Design and                     Description

6

Global URI

Web Protocols and Practice

URI (Uniform Resource Identifier) permits resources to reside anywhere on the Internet

URL (Uniform Resource Locator) shows the location of a copy of a resource

URN (Uniform Resource Name) is a unique name for a resource

URI is a superset of both URL and URN

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 7: HTTP Protocol Design and                     Description

7

Global URI

Web Protocols and Practice

URI

URN URL

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 8: HTTP Protocol Design and                     Description

8

HTTP Request

Web Protocols and Practice

Consider the following HTTP request:GET /foo.html HTTP/1.o

each request message consists of a Request-line

» Method: GET

» Resource: /foo.html

» HTTP version number: 1.0

General/Request/Entity Header (s) CRLF Entity body (optional)

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 9: HTTP Protocol Design and                     Description

9

HTTP Request Format

Web Protocols and Practice

GET /motd HTTP/1.0

Date: Wed,22 Mar 2000 08:09:01 GMT

Pragma: No-cache

From :[email protected]

User-Agent: Mozilla/4.03

<no entity body>

Request line

General headers

Request headers

Figure 6.1. An HTTP request message

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 10: HTTP Protocol Design and                     Description

10

HTTP Request Format

Web Protocols and Practice

PUT /motd HTTP/1.0

Date: Wed,22 Mar 2000 08:09:01 GMT

From :[email protected]

User-Agent: Mozilla/4.03

Request line

General header

Request headers

Figure 6.2. Another HTTP request message

Content-Length:23

Allow: GET, HEAD, PUT

Welcome to Comer’s Vax

Entity headers

Entity body

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 11: HTTP Protocol Design and                     Description

11

HTTP Response

Web Protocols and Practice

Consider the following HTTP response:HTTP/1.o 200 OK

Date: Wed,22 Mar 2000 08:01:01 GMT

Last-Modified: Wed,22 Mar 2000 02:16:33 GMT

Content-Length: 3913

<3,913 bytes of the current contents of /foo.html>

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 12: HTTP Protocol Design and                     Description

12

HTTP Response

Web Protocols and Practice

Each response message consists of a Status-line

» HTTP version number

» Status code (indicating success or failure)

» Status phrase

General/Response/Entity Header (s)» Date

» Last-Modified

» Content-Length

CRLF Entity body (optional)

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 13: HTTP Protocol Design and                     Description

13

HTTP Response Format

Web Protocols and Practice

HTTP/1.0 200 OK

Date: Wed,22 Mar 2000 08:09:01 GMT

Server: Netscape-Enterprise/3.51

Status line

General header

Response header

Figure 6.2. An HTTP response message

Content-Length:23

Welcome to Comer’s Vax

Entity header

Entity body

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 14: HTTP Protocol Design and                     Description

14

Statelessness

Web Protocols and Practice

HTTP is a stateless protocol. NNTP and FTP maintain some amount of state.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 15: HTTP Protocol Design and                     Description

15

Resource Metadata

Web Protocols and Practice

Metadata is information that relates to a resource but is not part of a resource itself.

Metadata includes: The size of a resource The type of the content The last modification time of the resource

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 16: HTTP Protocol Design and                     Description

16

HTTP Request methods

Web Protocols and Practice

A request method represents what action an HTTP sever should perform on the resource.

Some methods are: GET,HEAD,POSE,PUT,DELETE,LINK,UNLINK

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 17: HTTP Protocol Design and                     Description

17

HTTP Request methods

Web Protocols and Practice

Properties of a method are: Safety

» A request method that examines the state of a resource is a safe method.

» A method that can alter the state of the resource is not safe.

Idempotence» A method that its side effect is the same as multiple

identical requests.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 18: HTTP Protocol Design and                     Description

18

HTTP Request methods (GET)

Web Protocols and Practice

Is applied to the resource specified in the URL, and the generated response is the current value of the resource.

Is safe and idempotent. Could include arguments on the user’s input.

GET http://www.altavista.com/cgi-bin/query?q=foo

Can have modifier If-Modified-Since in header.GET /foo.html HTTP/1.0

If-Modified-Since: Sun, 12 Nov 2000 11:12:23 GMT

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 19: HTTP Protocol Design and                     Description

19

HTTP Request methods (HEAD)

Web Protocols and Practice

Is introduced to obtain just the metadata associated with a resource.

Is safe and idempotent. A HEAD request such as:

HEAD /foo.html HTTP/1.0

might retrunHTTP/1.0 200 OK

Content-Length: 3219

Last-Modified: Sun, 12 Nov 2000 11:12:23 GMT

Content-Type: text/html

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 20: HTTP Protocol Design and                     Description

20

HTTP Request methods (HEAD)

Web Protocols and Practice

Uses of HEAD method include: Debugging the server Determining recently resource changes

Not have request modifier such as If-Modified-Since

Has no request body

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 21: HTTP Protocol Design and                     Description

21

HTTP Request methods (POST)

Web Protocols and Practice

Is used to update an existing resource or provide input to a process handling data.

The body of the request includes the data. Is not safe and idempotent. The Content-Length header is required as part

of a POST request .

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 22: HTTP Protocol Design and                     Description

22

HTTP Request methods (PUT)

Web Protocols and Practice

Is similar to POST. Is not safe but idempotent.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 23: HTTP Protocol Design and                     Description

23

HTTP Request methods (DELETE)

Web Protocols and Practice

Is used to delete the resource remotely identified in Request-URI.

Is not safe but idempotent.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 24: HTTP Protocol Design and                     Description

24

HTTP Request methods (LINK and UNLINK)

Web Protocols and Practice

The LINK method permitted creation of links between the Request-URI and other resources.

The UNLINK method was used to delete links created via the LINK method.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 25: HTTP Protocol Design and                     Description

25

HTTP Headers

Web Protocols and Practice

General Headers Request Headers Response Headers Entity Headers

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 26: HTTP Protocol Design and                     Description

26

HTTP Headers

Web Protocols and Practice

HTTP header:Fieldname : Fieldvalue CRLF

A header is a free-format ASCII string representing the name with a value.

Headers are used to Alter the handling of a request Provide metadata about the resource Parameterize or describe a request or a response.

New headers in HTTP have arbitrary length. Headers are limited by CR and LF.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 27: HTTP Protocol Design and                     Description

27

HTTP Headers

Web Protocols and Practice

A message header could be A general header A request header A response header An entity header

The order of different headers are not significant but it is common to have

General header Request/Response header Entity header

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 28: HTTP Protocol Design and                     Description

28

General Headers

Web Protocols and Practice

General headers appear in both request and response messages.

The General headers are significant only to the message itself and not to the entity.

A general header has only two fields: Date

» Displayed in three different formats

Pragma» Are directives for recipient of the message» no-cache is the only directive

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 29: HTTP Protocol Design and                     Description

29

Request Headers

Web Protocols and Practice

A request header can be used by the client to send information with the request or to specify constraints on the sever handling the request.

Five request headers are: Authorization

» To include appropriate credentials required to access a resource

From» To include user’s email address

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 30: HTTP Protocol Design and                     Description

30

Request Headers

Web Protocols and Practice

If-Modified-Since Is a conditional header Retrieves resource if it has not changed since the

argument specified in the If-Modified-Since header.

Referer Lets the client include the URI of the resource from

which the request-URI was obtained.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 31: HTTP Protocol Design and                     Description

31

Request Headers

Web Protocols and Practice

User-Agent Can be used to include information about

» Version of the used browser» The client machine’s operating system version» Hardware details

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 32: HTTP Protocol Design and                     Description

32

Response Headers

Web Protocols and Practice

Response headers send additional information about the response and the server that originated the response.

If a response header is not recognized, it is assumed to be an entity header.

HTTP/1.0 defines three response headers: Location

» Is used to redirect the request to where the resource can be found.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 33: HTTP Protocol Design and                     Description

33

Response Headers

Web Protocols and Practice

Server» Can be used to include information about

Version of the origin server softwareConfiguration details

WWW-Authenticate» Is used to issue a challenge to the client seeking

access to an authenticated resource.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 34: HTTP Protocol Design and                     Description

34

Entity Headers

Web Protocols and Practice

An entity header is used to include information about the body of the entity or the resource.

Entity headers may be found in requests and in responses.

There are six entity headers Allow

» Is used to indicate the list of valid methods that can be applied to a resource.

Content-Type» Indicates the media type of the entity body

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 35: HTTP Protocol Design and                     Description

35

Entity Headers

Web Protocols and Practice

Content-Encoding» Indicates how the resource could be decoded into

the format indicated in the Content-Type.

Content-Length» Indicates the length of the entity body in bytes.

Expires» Indicates that the entity should be considered stale

after the time specified in the header.

Last-Modified» Indicates the time at which the resource was

modified last.

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 36: HTTP Protocol Design and                     Description

36

HTTP Response Classes

Web Protocols and Practice

The various kinds of responses are grouped into a set of response classes:

Informational class» 1xx

Success class» 2xx are generated after a server received and accepted

the HTTP request for processing 200 OK 201 Created 202 Accepted 204 No Content

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 37: HTTP Protocol Design and                     Description

37

HTTP Response Classes

Web Protocols and Practice

Redirection class» 3xx is used to inform the user agent that additional

action is needed to complete the request. 300 Multiple Choices 301 Moved Permanently 302 Moved Temporarily 304 Not Modified

Client error class» 4xx is used for identifying errors that made by

clients. 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found

HTTP PROTOCOL DESIGN AND

DESCRIPTION

Page 38: HTTP Protocol Design and                     Description

38

HTTP Response Classes

Web Protocols and Practice

Server error class» 5xx is used for identifying errors that made by the

server. 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable

HTTP PROTOCOL DESIGN AND

DESCRIPTION