Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0.

Similar presentations


Presentation on theme: "© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0."— Presentation transcript:

1 © Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0

2 HTTP request messages  HTTP request messages are sent by the agent to request that the server provide an object. Each request message includes a method (a command to indicate what is requested)  GET most common, gets an object  POST to send user (client) input information  HEAD (like GET, but no object in response)  Others in HTTP v1.1, e.g. PUT, DELETE Janice Regan © Sept. 2007-2016 1

3 HTTP request messages  GET the most commonly used method  request objects from a web server (expecting object to be returned)  POST  may send data entered into an online form to the webserver  For example if the data being sent was variables name and password the POST request would use a url with the form: www.somewhere.com/login?name&password Janice Regan © Sept. 2007-2016 2

4 HTTP request messages  HEAD (similar to GET)  response does not include requested object (primarily for debug)  Others available only in HTTP v1.1 (LATER)  PUT uploads file in entity body to path specified in URL field  DELETE deletes file specified in the URL field Janice Regan © Sept. 2007-2016 3

5 HTTP request message GET /templates/themes/clf/sfu/scripts/flyout.js HTTP/1.1\r\n Host: www.cs.sfu.ca\r\n User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0 Accept-Language: en-us,en;q=0.5\r\n Keep-Alive: 300\r\n Connection: keep-alive\r\n Referer: http://www.cs.sfu.ca/\r\n \r\n Janice Regan © Sept. 2007-2016 4 Request line: method URL version Header lines: header field name: (any number of lines permitted) Blank line \r\n at start of line indicates the end of the header lines Entity body

6 Request message format  A request line indicating  Method, URL, HTTP version  A header section including details of the request. Each line in the header section includes  A field name  A value for that field  A blank line follow Janice Regan © Sept. 2007-2016 5

7 Request message format  The entity body for a GET request message is empty so the CRLF indicating the blank line is the last thing in the request message  Request messages for other methods may include an entity body. For example a POST request message Janice Regan © Sept. 2007-2016 6

8 HTTP response messages  HTTP response messages: sent by the server to provide information and or to send objects back to the agent.  Each response begins with a status line containing the HTTP version a status and a phrase  Header with format the same as header for request  A blank line  Returned object is in the entity body Janice Regan © Sept. 2007-2016 7

9 HTTP response message HTTP/1.1 200 OK\r\n Date: Thu, 13 Sep 2007 13:54:26 GMT\r\n Server: Apache/2.0.59 (Unix) mod_fastcgi/2.4.2 SVN/1.4.4 DAV/2 mod_ssl/2.0.59 OpenSSL/0.9.8 PHP/4.4.7\r\n Keep-Alive: timeout=15, max=100\r\n Connection: Keep-Alive\r\n Content-Length: 452\r\n Content-Type: text/html; charset=ISO-8859-1\r\n \r\n Line-based text data: text/html Janice Regan © Sept. 2007-2016 8 Status line: version status code phrase Header lines: header field name: value CRLF Blank line (carriage return and line feed Entity body: actual object being returned

10 HTTP response messages  Each response begins with a status line: with the HTTP version a status and a phrase  The status is a number  The phrase is a name for the status in english  Each status is associated with one phrase (list in RFC)  OK if everything worked as expected  CREATED, ACCEPTED, MOVED, NOT FOUND, NOT IMPLEMENTED, … (more in your text, see RFCs for complete list) Janice Regan © Sept. 2007-2016 9

11 What if there is a problem?  Status code appears in 1st line in response message. Example codes:  200 OK  301 Moved Permanently (location given later in msg)  400 Bad Request (request not understood by server)  404 Not Found ( requested doc not found on server)  505 HTTP Version Not Supported Janice Regan © Sept. 2007-2016 10

12 Cookies  Used by web-sites to identify users and keep track of information about users  Need 4 components to use cookies  A cookie file kept on the users machine managed by the users browser  A data-base of information kept at the website  Information passed between the two above using both the a cookie header line in the HTTP request message and a second cookie header line in the HTTP reply message Janice Regan © Sept. 2007-2016 11

13 Example using cookies (text)  Susan uses her PC to access the internet  She visits an e-shopping site for the 1st time  Her interaction with the site includes sending HTTP requests to the site create  A unique ID stored in a cookie on her computer  An entry in the e-shopping sites database for her account Janice Regan © Sept. 2007-2016 12

14 Using Cookies: save state CLIENT (susan)SERVER Janice Regan © Sept. 2007-2016 13 Myshop 2234 Created Cookie file database HTTP request Myshop server Creates ID 124 Places in DB HTTP response Set-cookie: 124 Myshop 2234 ID 124

15 Using Cookies: later CLIENT (susan) SERVER Janice Regan © Sept. 2007-2016 14 Myshop 2234 ID 124 Created Cookie file database HTTP request Cookie: 124 Cookie specific actions HTTP response Access information Later can be immediately after creating cookie, or some time later

16 Controversy  Cookies can be considered an invasion of privacy or a security risk?  How do you avoid the risk?  What happens if you remove cookies?  What happens when sites try to prevent you from removing their cookies? Janice Regan © Sept. 2007-2016 15

17 Caching  All objects used to display a requested web page may be stored in a cache  When your request the same page or a another page containing some of the same objects, the objects you already have in the cache may not need to be downloaded again, they can simply be loaded from the cache Janice Regan © Sept. 2007-2016 16

18 Proxy web cache  A proxy server is a host that provides a service to users. One such service may be a web cache  To the client sending the HTTP request the Proxy server appears to be the web server  To the web server the Proxy server appears to be the web client  Proxy servers are most commonly used by ISPs, institutions (e.g. university, government) or companies Janice Regan © Sept. 2007-2016 17

19 HTTP request using a web cache  The local agent (browser) on the users host connects to the proxy server using TCP then makes an HTTP request (for a particular object) to the proxy server  The proxy server’s web cache application checks the web cache to see if the requested object is in the cache  If the requested object is in the cache, the web cache application will send the object from the cache to the local agent in an HTTP reply.  This reduces response time and traffic on external access link (to server) Janice Regan © Sept. 2007-2016 18

20 HTTP request using a web cache  If the requested object is not in the cache the web cache will make a TCP connection to the web server, send a HTTP Get requesting the object, and receive an HTTP reply containing the object from the web server.  The object returned in the HTTP response from the web server, will be placed in an HTTP reply to the client and then sent to the HTTP client  The object returned in the HTTP response will also be placed in the web cache Janice Regan © Sept. 2007-2016 19

21 Janice Regan © Sept. 2007-2016 20 Client 1 Client 2 Proxy Server Server (1) Client 1 makes HTTP request Proxy Server Cache (3) Proxy server makes HTTP request (2) Proxy checks cache, item in HTTP request is not present (4) Server sends HTTP reply (5) Add HTTP reply (6) Proxy Server sends HTTP reply (7) Client 2 makes HTTP request (9) Proxy Server sends HTTP reply (8) Get cached HTTP reply

22 Why does caching help  Reduces load on the Internet, fewer copies of the same object are requested  Improved security  Reducing bottlenecks in bandwidth Janice Regan © Sept. 2007-2016 21 Host with network web cache Local network 10Mbps Connection to Internet 1.5Mbps clients Web servers

23 Caching example (from text)  Average object size, 100k bits  Average request rate from institution net 15 / sec  Utilization of institutional network 15 * 100K / 10 Mbps = 15% (14.3%, if 1Mb = 2 20 )  Utilization internet connection for requests (no cache) 15 * 100K /1.5 Mbps = 100% (97.7%, if 1Mb = 2 20 ) very high utilization implies major delays (minutes) Janice Regan © Sept. 2007-2016 22

24 Caching solution 1 (from text)  Average object size, 100k bits  Average request rate from institution net 15 / sec  Upgrade speed of internet link (expensive)  Utilization of institutional network 15 * 100K /10 Mbps = 15%  Utilization internet connection for requests (no cache) 15 * 100K /10 Mbps = 15% modest utilization implies minor delays (msecs) Janice Regan © Sept. 2007-2016 23

25 Caching solution 2 (from text)  Average object size, 100k bits  Average request rate from institution net 15 / sec  Install a cache on the local network. Assume 40% of requests are satisfied by the cache  Utilization of institutional network 15 * 100K / 1O Mbps = 15%  Utilization internet connection for requests (with cache) (1-0.4) * 15 * 100K /1.5 Mbps = 60% significant utilization implies small delays (10 msecs) Janice Regan © Sept. 2007-2016 24

26 Caching  Caching can increase efficiency  However, one must also assure that the objects in the cache are current.  If an object has changed since it was downloaded, then it should be downloaded again before being displayed as part of the web page  Don’t want to display material that is out of date Janice Regan © Sept. 2007-2016 25

27 Keeping the cache current (1)  How do we assure that the objects displayed on our webpage are up to date  If the object is cached there is a possibility it has changed since it was downloaded  Before we display the object our cache sends a conditional HTTP get message to the server.  Have the server send back the cached information again only it has changed. Janice Regan © Sept. 2007-2016 26

28 Keeping the cache current (2)  To make a Get message conditional the header section must include a If-Modified-Since: header line If-Modified-Since: Wed, 2 May 2003 10:26:11  The date in the header line is the Last-Modified time that was returned in the HTTP response that originally downloaded the object (the date is saved with the object) Janice Regan © Sept. 2007-2016 27

29 Keeping the cache current (3)  When the request is processed the web server will compare its Last-Modified date of its local copy of the object with the If-Modified-Since date in the request packet  If the object has not been modified since it was last downloaded the server will return a response that includes a status of Not Modified, and does not include the object in the entity body  If the object has been modified the modified object will be returned and replace the old copy in the cache, and be displayed as part of the webpage Janice Regan © Sept. 2007-2016 28


Download ppt "© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0."

Similar presentations


Ads by Google