Download presentation
Presentation is loading. Please wait.
Published byJacob Barnett Modified over 9 years ago
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-2013 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-2013 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-2013 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-2013 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-2013 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-2013 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-2013 7
9
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-2013 8
10
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-2013 9
11
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-2013 10 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
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-2013 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-2013 12
14
Using Cookies: save state CLIENT (susan)SERVER Janice Regan © Sept. 2007-2013 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-2013 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
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-2013 15
17
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-2013 16
18
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-2013 17
19
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-2013 18
20
Janice Regan © Sept. 2007-2013 19 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
21
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-2013 20 Host with network web cache Local network 10Mbps Connection to Internet 1.5Mbps clients Web servers
22
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% Utilization internet connection for requests (no cache) 15 * 100K /1.5 Mbps = 100% very high utilization implies major delays (minutes) Janice Regan © Sept. 2007-2013 21
23
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 / 1O Mbps = 15% Utilization internet connection for requests (no cache) 15 * 100K /10 Mbps = 15% modest utilization implies minor delays (msecs) Janice Regan © Sept. 2007-2013 22
24
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 (10s msecs) Janice Regan © Sept. 2007-2013 23
25
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-2013 24
26
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-2013 25
27
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-2013 26
28
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-2013 27
29
© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking FTTP 28
30
FTP File Transfer Protocol An application layer communication protocol used to transfer files from one host to another Often used for downloading files on the Internet We can use FTP without connecting through the WWW (uses port 21) For detailed information about HTTP see RFC 959 Janice Regan © Sept. 2007-2013 29
31
File transfer protocol When we want to copy a file from a remote site we can use FTP When an FTP request is made first a TCP connection is made just to exchange control information. This is called the control connection A second TCP connection will later be made to do the actual transfer of the requested file. This is called the data connection Janice Regan © Sept. 2007-2013 30
32
Control information permissions and passwords indicating that the user attempting the download is permitted to access the file requested for download. Negotiation of the properties (like port) of the data connection Keep track of the state of the user, for example where in the remote directory tree he is, so the file to transfer can be identified Janice Regan © Sept. 2007-2013 31
33
Common Channel Signaling Signals travel independently from data, over a separate common channel The separate channel handles control messages for a number of connections simultaneously. For FTP each file transfers on a separate channel, all transfers are managed using a single channel This makes the signaling protocol and the network architecture more complicated Janice Regan © Sept. 2007-2013 32
34
Steps: using FTP (1) Client contacts server (port 21) Client logs in (to control channel), provides password to verify that he /she has access to the available files Client browses files and chooses desired file or files (using LIST, CWD, LS, CD) Client requests first desired file (using RETR in Windows or GET in linux/unix) Janice Regan © Sept. 2007-2013 33
35
Steps: using FTP (2) Server receives transfer command, opens a 2 nd TCP connection and transfers the file though the 2 nd TCP connection (port 20) When the file has completed transfer the 2 nd TCP connection is closed. Server opens another connection to transfer next requested file. Janice Regan © Sept. 2007-2013 34
36
Examples of FTP Commands sample commands used in the control channel USER username PASS password LIST return list of file in current directory RETR filename retrieves (gets) file STOR filename stores (puts) file onto remote host Janice Regan © Sept. 2007-2013 35
37
Examples of FTP replies 331 Username OK, password required 425 Can’t open data connection 452 Error writing file 125 data connection already open; transfer starting Janice Regan © Sept. 2007-2013 36
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.