Application Layer: The World Wide Web and HTTP Protocol

Overview of the World Wide Web and HTTP

  • World Wide Web (WWW) Definition: An information system where documents and other resources are identified by Uniform Resource Locators (URLs), interlinked by hypertext, and accessed over the Internet.

  • Components of Web Architecture:

    • URL (Uniform Resource Locator): Uniquely identifies web resources.

    • Host Name: Specifies the host server domain (e.g., www.unt.edu).

    • Path Name: Specifies the path location of the file on the host server (e.g., /index.html).

    • Example full URL: www.unt.edu/index.html.


    URL Structure Diagram
    • HTML (HyperText Markup Language): Language for creating hypertext documents.

    • HTTP (HyperText Transfer Protocol): Application-layer protocol used for transferring web resources across the Internet.

  • Web Page Composition and Objects:

    • A web page consists of a base HTML file that typically references and hyperlinks other web objects.

    • Each web object is individually addressable by its unique URL.

    • Web objects can be HTML files, images, scripts, audio, video, etc.

    • Objects referenced on a single page can be stored on the same web server or across different web servers.

  • Web Browsers: Procure web pages and objects from web servers and display them to users.

  • Historical Background: Sir Tim Berners-Lee invented the World Wide Web at CERN in 19891989.

Core Technical Characteristics of HTTP

  • Transport Protocol: HTTP uses TCP (Transmission Control Protocol) at the transport layer.

    • Server listens for incoming connections on port 8080.

    • Client initiates a TCP connection handshake, exchanges HTTP messages, and closes the connection.

  • Protocol Specifications:

    • HTTP/1.0: Specified in RFC 1945.

    • HTTP/1.1: Specified in RFC 2616.

    • Text Format: ASCII (human-readable) text format.

    • Message Types: Standardized into two message types: request and response.

  • Client-Server Model:

    • Clients: Request and receive web objects via HTTP and display them.

    • Servers: Store and send web objects in response to HTTP requests.

  • Statelessness:

    • HTTP is a stateless protocol: the server maintains no information about past client requests.

    • Rationale: Protocols that maintain state tend to be complex, requiring intricate mechanisms to track state across server crashes, network disruptions, or client failures.

HTTP Request Message Format and Structure

  • Request Structure Breakdown:

    • Request Line: Contains method, space (sp), URL, space (sp), version, carriage return (cr or \r), and line feed (lf or ).

    • Header Lines: Formatted as header field name:, space (sp), value, carriage return (cr), and line feed (lf).

    • Blank Line: A line consisting of carriage return and line feed (cr lf or \r ) at the start of the line indicates the end of the header lines.

    • Entity Body (Message Body): Payload area containing data (used with methods like POST or PUT).


  • Concrete Request Message Example:

  GET /index.html HTTP/1.1\r

  Host: www.unt.edu\r

  User-Agent: Mozilla/5.0 (Macintosh; MacOS X 15.6.1) Chrome/144.0.7559.110\r

  Accept: text/html,application/xhtml+xml,image/webp,image/apng\r

  Accept-Language: en-us,en\r

  Connection: keep-alive\r

  \r\n
  • Request Line: GET /index.html HTTP/1.1

  • Header Lines: Include Host, User-Agent, Accept, Accept-Language, and Connection headers.

  • End of Headers: Marked by an isolated \r

Key Methods of HTTP Requests

GET Method:

  • Requests data/resources from the server.

  • User data can be embedded directly in the URL query field following a ? character.

    • Example: www.google.com/search?q=unt

POST Method:

  • Used for transmitting web form data filled out by a user.

  • Data is included in the entity body of the request message rather than in the URL.

  • Server returns a dynamic web page based on user inputs provided in the form.

PUT Method:

  • Uploads a new object to the server.

  • Completely replaces the file existing at the specified URL with the content provided in the entity body of the PUT request.

HEAD Method:

  • Requests the server to respond with headers pertaining to the specified URL only (omits the entity body).

  • Commonly used for debugging, testing resource existence, or checking metadata.

DELETE Method:

  • Deletes a specified object/file hosted at the target URL on the server.

  • Not commonly supported or allowed on standard public web servers due to security concerns.

HTTP Response Message Format and Structure

status line ->     HTTP/1.1 200 OK 
                  - Date: Wed, 2 Sep 2026 18:53:20 GMT 
                 | Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k fips 
Header lines  ---| PHP/7.4.9 Perl/v5.16.3 
                 | Last-Modified: Tue, 1 Sep 2026 10:57:50 GMT 
                 | Content-Length: 2651 
                 | Content-Type: text/html; charset=UTF-8 
                 - \r\n 
Requested HTML File->   data data data data data ...
  • Response Structure Breakdown:

  • Status Line: Contains protocol version, space sp), status code, space sp), status phrase, carriage return cr), and line feed lf).

  • Header Lines: Formatted as header field name:, space sp), value, carriage return cr), and line feed lf).

  • Blank Line: Carriage return and line feed cr lf or `\r`) indicating the end of response headers.

* Entity Body: Contains the requested resource file/data (e.g., HTML data).

*


Standard HTTP Response Status Codes

  • 1XX Informational Status Codes:

    • 100: Continue

    • 101: Switching Protocols

    • 102: Processing

  • 2XX Success Status Codes:

    • 200: OK

    • 201: Created

    • 202: Accepted

    • 203: Non-authoritative Information

    • 204: No Content

    • 205: Reset Content

    • 206: Partial Content

  • 3XX Redirectional Status Codes:

    • 300: Multiple Choices

    • 301: Moved Permanently

    • 302: Found

    • 303: See Other

    • 304: Not Modified

    • 305: Use Proxy

    • 307: Temporary Redirect

    • 308: Permanent Redirect

  • 4XX Client Error Status Codes:

    • 400: Bad Request

    • 401: Unauthorized

    • 402: Payment Required

    • 403: Forbidden

    • 404: Not Found

  • 5XX Server Error Status Codes:

    • 500: Internal Server Error

    • 501: Not Implemented

    • 502: Bad Gateway

    • 503: Service Unavailable

    • 504: Gateway Timeout

    • 505: HTTP Version Not Supported

    • 506: Variant Also Negotiates

    • 507: Insufficient Storage

Common HTTP Message Headers


  • Request Headers:

    • User-Agent: Information about the client browser software and host platform.

    • Accept: Types of media/pages the client can handle.

    • Accept-Charset: Character sets acceptable to the client.

    • Accept-Encoding: Encodings acceptable to the client.

    • Accept-Language: Natural languages acceptable to the client.

    • Host: The server's DNS host name.

    • Authorization: Credentials list for client authentication.

    • Cookie: Sends a previously set HTTP cookie back to the server.

  • Response Headers:

    • Server: Information about server software and environment.

    • Content-Encoding: Encoding algorithm applied to content (e.g., gzip).

    • Content-Language: Natural language of the document content.

    • Content-Length: Length of payload/page in bytes.

    • Content-Type: MIME type of page/resource.

    • Last-Modified: Time and date the resource was last modified.

    • Location: Redirect command instructing the client browser to request a different URL.

    • Accept-Ranges: Indicates server support for byte-range requests.

    • Set-Cookie: Directs the client browser to save an HTTP cookie.

  • Headers Applicable to Both Requests and Responses:

    • Date: Date and time the message was sent.

    • Upgrade: Protocol the sender wishes to switch to.

Real-World Web Problems and Evolution of HTTP

  • Conditional GET (Web Caching Optimization):

    • Goal: Prevent unnecessary transmission of objects over the network if the client already possesses an up-to-date cached copy, saving bandwidth and network overhead.

    • Mechanism:

    • Client sends a GET request containing an If-Modified-Since: <date> header specifying the timestamp of the cached copy.

    • Server checks whether the resource was modified after <date>.

    • If object was NOT modified: Server responds with HTTP/1.0 304 Not Modified containing an empty message body.

    • If object WAS modified: Server responds with HTTP/1.0 200 OK followed by the requested object payload.

  • Connection Management: Non-Persistent vs Persistent HTTP:

    • Non-Persistent HTTP (HTTP/1.0):

    • Step-by-step transaction sequence for accessing a URL (e.g., www.unt.edu/index.html containing text, images, and videos):

      1. HTTP client initiates a TCP connection to the HTTP server at www.unt.edu on port 8080.

      2. HTTP server waiting at port 8080 accepts the TCP connection and notifies the client.

      3. HTTP client sends an HTTP request message (containing the URL index.html) into the socket.

      4. HTTP server receives the request, forms a response containing index.html, and sends it into its socket.

      5. HTTP client receives the response containing the HTML file and displays it. Upon parsing, it identifies references to embedded image and video objects.

      6. HTTP server closes the TCP connection.

      7. HTTP client terminates its TCP connection. It then repeats steps 1, 3, and 5 independently for every referenced object.

    • Performance Metrics (Round Trip Time - RTT):

      • RTT: Time required for a small packet to travel from client to server and back.

      • TCP Connection Handshake Latency: 1×RTT1 \times \text{RTT}.

      • HTTP Request and Response Header Latency: 1×RTT1 \times \text{RTT}.

      • Formula for response time per object:  Total Response Time per Object=2×RTT+file transmission time\text{Total Response Time per Object} = 2 \times \text{RTT} + \text{file transmission time}

    • Shortcomings of Non-Persistent HTTP:

      • Incurs 2×RTT2 \times \text{RTT} overhead per object.

      • Causes significant Operating System (OS) overhead due to opening and closing distinct TCP connections for every single object.

      • Led browsers to open multiple TCP connections in parallel to fetch objects, adding network stress.

    • Persistent HTTP (HTTP/1.1):

      • Server leaves the TCP connection open after sending its response.

      • Subsequent HTTP messages between the same client and server are transmitted across the pre-existing open connection.

      • Client sends requests immediately upon encountering references to web objects.

      • Performance advantage: Response time drops close to 1×RTT1 \times \text{RTT} for all referenced objects after the initial object, cutting average delivery time approximately in half.