Hyper Text Transfer Protocol HTTP Hyper Text Transfer

  • Slides: 22
Download presentation
Hyper. Text Transfer Protocol (HTTP)

Hyper. Text Transfer Protocol (HTTP)

Hyper. Text Transfer Protocol (HTTP) q HTTP is the protocol that supports communication between

Hyper. Text Transfer Protocol (HTTP) q HTTP is the protocol that supports communication between web browsers and web servers. q A “Web Server” is a HTTP server q Most clients/servers today speak version 1. 1, but 1. 0 is also in use. RFC 1945 (HTTP 1. 0) v RFC 2616 (HTTP 1. 1) v HTTP 2

From the RFC q “HTTP is an application-level protocol with the lightness and speed

From the RFC q “HTTP is an application-level protocol with the lightness and speed necessary for distributed, hypermedia information systems. ” q Transport Independence v The HTTP protocol generally takes place over a TCP connection, v but the protocol itself is not dependent on a specific transport layer. HTTP 3

Request - Response q HTTP has a simple structure: v client sends a request

Request - Response q HTTP has a simple structure: v client sends a request v server returns a reply. q The “well known” TCP port for HTTP servers is port 80. v Other ports can be used as well. . . HTTP 4

HTTP 1. 0+ Request q Lines of text (ASCII). q Lines end with CRLF

HTTP 1. 0+ Request q Lines of text (ASCII). q Lines end with CRLF “rn” q First line is called “Request-Line” Request-Line Headers. . . blank line Content. . . HTTP 5

Request Line Method URI HTTP-Versionrn q The request line contains 3 tokens (words). q

Request Line Method URI HTTP-Versionrn q The request line contains 3 tokens (words). q space characters “ “ separate the tokens. q Newline (n) seems to work by itself v but the protocol requires CRLF HTTP 6

Request Method q The Request Method can be: GET PUT HEAD POST DELETE TRACE

Request Method q The Request Method can be: GET PUT HEAD POST DELETE TRACE OPTIONS future expansion is supported q GET, HEAD and POST are supported everywhere (including Lab 2!). q HTTP 1. 1 servers often support PUT, DELETE, OPTIONS & TRACE. HTTP 7

Methods q GET: v Typically used to retrieve an HTML document q HEAD: v

Methods q GET: v Typically used to retrieve an HTML document q HEAD: v retrieve meta-information about the URI. used to find out if a document has changed q POST: v retrieve information identified by the URI. send information to a URI and retrieve result. used to submit a form HTTP 8

More Methods q PUT: Store information in location named by URI. q DELETE: remove

More Methods q PUT: Store information in location named by URI. q DELETE: remove entity identified by URI. q TRACE: used to trace HTTP forwarding through proxies, tunnels, etc. q OPTIONS: used to determine the capabilities of the server, or characteristics of a named resource. HTTP 9

The Header Lines q Request Headers provide information to the server about the client

The Header Lines q Request Headers provide information to the server about the client what kind of client v what kind of content will be accepted v who is making the request v q Each header line contains v an attribute name followed by a “: ” followed by a space and the attribute value. q There can be 0 headers (HTTP 1. 0) q HTTP 1. 1 requires a Host: header HTTP 10

Example HTTP Headers Accept: text/html Host: www. cse. unr. edu From: mgunes@cse. unr. edu

Example HTTP Headers Accept: text/html Host: www. cse. unr. edu From: mgunes@cse. unr. edu User-Agent: Mozilla/4. 0 Referer: http: //www. unr. edu/ HTTP 11

End of the Headers q Each header ends with a CRLF ( rn )

End of the Headers q Each header ends with a CRLF ( rn ) q The end of the header section is marked with a blank line. v just CRLF q For GET and HEAD requests, the end of the headers is the end of the request! HTTP 12

POST q A POST request includes some content (some data) after the headers (after

POST q A POST request includes some content (some data) after the headers (after the blank line). q There is no format for the data (just raw bytes). q A POST request must include a Content- Length line in the headers: Content-length: 267 HTTP 13

Example POST Request POST /~mgunes/cpe 401/grades. cgi HTTP/1. 1 Accept: */* Host: www. cse.

Example POST Request POST /~mgunes/cpe 401/grades. cgi HTTP/1. 1 Accept: */* Host: www. cse. unr. edu User-Agent: Secret. Agent V 2. 3 Content-Length: 35 Referer: http: //www. unr. edu/ stuid=6660182722&item=test 1&grade=99 HTTP 14

Example GET Request GET /~mgunes/cpe 401/lab 1. htm HTTP/1. 1 Accept: */* Host: www.

Example GET Request GET /~mgunes/cpe 401/lab 1. htm HTTP/1. 1 Accept: */* Host: www. cse. unr. edu User-Agent: Internet Explorer From: mgunes@cse. unr. edu Referer: http: //www. unr. edu/ There is a blank line here! HTTP 15

HTTP Response q ASCII Status Line q Headers Section Status-Line Headers. . . blank

HTTP Response q ASCII Status Line q Headers Section Status-Line Headers. . . blank line Content. . . q Content can be anything (not just text) v typically an HTML document or some kind of image. HTTP 16

Response Status Line HTTP-Version Status-Code Message q Status Code is 3 digit number (for

Response Status Line HTTP-Version Status-Code Message q Status Code is 3 digit number (for computers) v 1 xx Informational v 2 xx Success v 3 xx Redirection v 4 xx Client Error v 5 xx Server Error q Message is text (for humans) HTTP 17

Example Status Lines HTTP/1. 0 200 OK HTTP/1. 0 301 Moved Permanently HTTP/1. 0

Example Status Lines HTTP/1. 0 200 OK HTTP/1. 0 301 Moved Permanently HTTP/1. 0 400 Bad Request HTTP/1. 0 500 Internal Server Error HTTP 18

Response Headers q Provide the client with information about the returned entity (document). what

Response Headers q Provide the client with information about the returned entity (document). what kind of document v how big the document is v how the document is encoded v when the document was last modified v q Response headers end with blank line HTTP 19

Response Header Examples Date: Wed, 30 Jan 2002 12: 48: 17 EST Server: Apache/1.

Response Header Examples Date: Wed, 30 Jan 2002 12: 48: 17 EST Server: Apache/1. 17 Content-Type: text/html Content-Length: 1756 Content-Encoding: gzip HTTP 20

Content q Content can be anything (sequence of raw bytes). q Content-Length header is

Content q Content can be anything (sequence of raw bytes). q Content-Length header is required for any response that includes content. q Content-Type header also required. HTTP 21

HTTP Proxy Server Browser Proxy HTTP Server HTTP 22

HTTP Proxy Server Browser Proxy HTTP Server HTTP 22