Ch02-03-HTTP by liaoxiuli


									Application Layer: HTTP

      Bahjat Qazzaz
            Web and HTTP
• Web page consists of objects
• Object can be HTML file, JPEG image, Java
  applet, audio clip, …
• Web page consists of base HTML-file which
  includes several referenced objects
• Each object is addressable by a URL
• Example URL:

          host name           path name
                HTTP overview
HTTP: hypertext
 transfer protocol
                               PC running
• Web’s application layer       Explorer
• client/server model
   – client: browser that                       Server
      requests, receives,                     Apache Web
      “displays” Web objects                    server

   – server: Web server
                                Mac running
      sends objects in           Navigator
      response to requests
 HTTP overview (continued)
Uses TCP:
• client initiates TCP connection (uses and
  creates socket) to server, port 80
• server accepts TCP connection from client
• HTTP messages (application-layer protocol
  messages) exchanged between browser
  (HTTP client) and Web server (HTTP server)
• TCP connection closed
More details:
   – client sends http request through its socket interface
   – the message becomes in the hand of TCP which
     provides reliable transfer. Thus, http request will
     eventually arrive the server, and http need not worry
     about loss of data.
  – The server also responds through sockets
  – Server does not store any store data about
    the client
  – So, http is considered as stateless protocol
HTTP is “stateless”
• server maintains no information about past
  client requests
         HTTP connections
Nonpersistent HTTP     Persistent HTTP
• Only one object is   • Multiple objects can
  sent over a TCP        be sent over single
  connection.            TCP connection
• HTTP/1.0 uses          between client and
  nonpersistent HTTP     server.
                       • HTTP/1.1 uses
                         connections in default
                 Nonpersistent HTTP                         (contains text,
                                                           references to 10
Suppose user enters URL                                      jpeg images)
   1a. HTTP client initiates TCP
     connection to HTTP server   1b. HTTP server at host
       (process) at
                               on port
                                        waiting for TCP connection
                                        at port 80. “accepts”
   2. HTTP client sends HTTP            connection, notifying client
       request message into TCP
       connection socket. Message    3. HTTP server receives
       indicates that client wants     request message, forms
       object                          response message
       someDepartment/home.html        containing requested object,
                                       and sends message into its
time                                   socket
         Nonpersistent HTTP (cont.)
                                           4. HTTP server closes TCP
       5. HTTP client receives response
          message containing html file,
          displays html. Parsing html
          file, finds 10 referenced jpeg
time      objects
       6. Steps 1-4 repeated for each
          of 10 jpeg objects
     Response time modeling
Definition of RTT (round-trip
   time: time to send a small
   packet to travel from client
                                  initiate TCP
   to server and back.            connection
Response time:                             RTT
• one RTT to initiate TCP              file
   connection                                              time to
• one RTT for HTTP                       file

   request and first few bytes           received
   of HTTP response to
   return                                        time   time

• file transmission time
total = 2RTT+transmit time
                 Persistent HTTP
Nonpersistent HTTP issues:      Persistent without pipelining:
• requires 2 RTTs per object    • client issues new request
• OS must allocate host           only when previous
  resources for each TCP          response has been received
                                • one RTT for each referenced
• but browsers often open         object
  parallel TCP connections to
  fetch referenced objects      Persistent with pipelining:
Persistent HTTP                 • default in HTTP/1.1
• server leaves connection      • client sends requests as
  open after sending response     soon as it encounters a
• subsequent HTTP messages        referenced object
  between same client/server    • as little as one RTT for all
  are sent over connection        the referenced objects
            HTTP request message
 • two types of HTTP messages: request, response
 • HTTP request message:
    – ASCII (human-readable format)
  request line
 (GET, POST,         GET /somedir/page.html HTTP/1.1
HEAD commands)       Host:
                     User-agent: Mozilla/4.0
             header Connection: close
               lines Accept-language:fr

 Carriage return,
     line feed      (extra carriage return, line feed)
  indicates end
    of message
HTTP request message: general format
         Uploading form input
Post method:
• Web page often
  includes form input      URL method:
• Input is uploaded to     • Uses GET method
  server in entity body    • Input is uploaded in
                             URL field of request

               Method types
HTTP/1.0                      HTTP/1.1
• GET                         • GET, POST, HEAD
• POST                        • PUT
• HEAD                          – uploads file in entity
  – asks server to leave          body to path specified
    requested object out of       in URL field
    response                  • DELETE
                                – deletes file specified in
                                  the URL field
      HTTP response message
  status line
 status code        HTTP/1.1 200 OK
status phrase)      Connection: close
                    Date: Thu, 06 Aug 1998 12:00:15 GMT
                    Server: Apache/1.3.0 (Unix)
                    Last-Modified: Mon, 22 Jun 1998 ...
                    Content-Length: 6821
                    Content-Type: text/html

                    data data data data data ...
data, e.g.,
HTML file
     HTTP response status codes
In first line in response message.
A few sample codes:
200 OK
   – request succeeded, requested object included in this
301 Moved Permanently
   – requested object moved, new location specified later in this
     message (Location:)
400 Bad Request
   – request message not understood by server
404 Not Found
   – requested document not found on this server
505 HTTP Version Not Supported
    Conditional GET: client-side caching
                               client                        server
• Goal: don’t send object if
  client has up-to-date                  HTTP request msg
  cached version                              <date>          object
• client: specify date of
                                          HTTP response       modified
  cached copy in HTTP                       HTTP/1.0
  request                               304 Not Modified
     <date>                             HTTP request msg
• server: response contains             If-modified-since:
                                              <date>           object
  no object if cached copy                                     modified
  is up-to-date:                          HTTP response
                                         HTTP/1.0 200 OK
   HTTP/1.0 304 Not
 Trying out HTTP (client side) for yourself

1. Telnet to your favorite Web server:
                                  Opens TCP connection to port 80
   telnet 80
                                  (default HTTP server port) at
                         Anything typed in
                                  sent to port 80 at

2. Type in a GET HTTP request:
     GET /index.shtml HTTP/1.0            By typing this in (hit carriage
                                          return twice), you send
                                          this minimal (but complete)
                                          GET request to HTTP server

3. Look at response message sent by HTTP
• Cookies: allow sites to keep track of users
How does it works:
   – Web site creates and Identification number for the new user
   – The server creates an entry for the new user in its database
     indexed by the ID num.
   – The server includes in the http response a Set-cookie (e.g.
   – Client’s browser receives the response, sees the Set-cookie,
     appends a line to the cookie file that the browser manages.
   – The line includes the host name of the server and the ID.
   – Each time the client browses (connects to) the site, the browser
     consults the cookie file, extracts the id, and puts it in the cookie
     header line of the HTTP request.
• Cookies can create session layer at top of
  stateless HTTP !!!!!!

Explain……….read last two paragraphs of
 page 99
            Web caches / proxy
• Web caches or Proxy server
   Keeps copies of recently requested objects.
   Then what happens:
   – Browser opens a TCP connection to the web cache and sends
     its request to it
   – The cache sends the requested data (if available locally) to the
     clients browser
   – If the data is not available locally, the proxy opens a TCP
     connection to the web server forwarding the client’s request
   – The web cache receives the response, stores copy in its storage
     and forwards a copy to the client.
Notice: cache may send If-modified-since message…why!
Answer is in page:105 and 106
        Web caches / proxy
• Impact of web cache
  – Reduces response time
  – Reduces traffic on the univ link
  – Increase the overall performance of the
   Read pages 102+103+104+105 of the book
                 For performance

To top