HTTP Protocol
HTTP Protocol
HTTP Protocol
<html><body><h1>It works!</h1></body></html>
Server response
• The browser receives the response message,
interprets the message and displays the contents
of the message on the browser's window
according to the media type of the response (as
in the Content-Type response header). Common
media type include "text/plain", "text/html",
"image/gif", "image/jpeg", "audio/mpeg",
"video/mpeg", "application/msword", and
"application/pdf".
HTTP over TCP/IP
• HTTP is a client-server application-level protocol.
It typically runs over a TCP/IP connection, as
illustrated. (HTTP needs not run on TCP/IP. It only
presumes a reliable transport. Any transport
protocols that provide such guarantees can be
used.)
• TCP/IP (Transmission Control Protocol/Internet
Protocol) is a set of transport and network-layer
protocols for machines to communicate with
each other over the network
HTTP over TCP/IP
Internet Protocol (IP)
• IP is a network-layer protocol, deals with network
addressing and routing. In an IP network, each machine
is assigned an unique IP address (e.g., 165.1.2.3), and
the IP software is responsible for routing a message
from the source IP to the destination IP. In IPv4 (IP
version 4), the IP address consists of 4 bytes, each
ranges from 0 to 255, separated by dots, which is called
a quad-dotted form.
• The DNS (Domain Name Service) translates the
domain name into the IP address (via distributed
lookup tables). A special IP address 127.0.0.1 always
refers to your own machine. It's domain name is
"localhost" and can be used for local loopback testing.
Transmission Control Protocol (TCP)
• TCP is a transport-layer protocol, responsible for
establish a connection between two machines.
• TCP consists of 2 protocols: TCP and UDP (User
Datagram Package). TCP is reliable, each packet has a
sequence number, and an acknowledgement is
expected. A packet will be re-transmitted if it is not
received by the receiver. Packet delivery is guaranteed
in TCP.
• UDP does not guarantee packet delivery, and is
therefore not reliable. However, UDP has less network
overhead and can be used for applications such as
video and audio streaming, where reliability is not
critical.
Transmission Control Protocol (TCP)
• TCP multiplexes applications within an IP
machine. For each IP machine, TCP supports
(multiplexes) up to 65536 ports (or sockets), from
port number 0 to 65535. An application, such as
HTTP or FTP, runs (or listens) at a particular port
number for incoming requests. Port 0 to 1023 are
pre-assigned to popular protocols, e.g., HTTP at
80, FTP at 21, Telnet at 23, SMTP at 25, NNTP at
119, and DNS at 53. Port 1024 and above are
available to the users.
• Although TCP port 80 is pre-assigned to HTTP, as the default
HTTP port number, this does not prohibit you from running
an HTTP server at other user-assigned port number (1024-
65535) such as 8000, 8080, especially for test server.
• You could also run multiple HTTP servers in the same
machine on different port numbers. When a client issues a
URL without explicitly stating the port number, the browser
will connect to the default port number 80 of host
http://www.nowhere123.com/docs/index.html,
• You need to explicitly specify the port number in the URL, if
the server is listening at port 8000 and not the default port
80.
http://www.nowhere123.com:8000/docs/index.html
• In brief, to communicate over TCP/IP, you need to know
(a) IP address or hostname, (b) Port number.
HTTP versions
• The HTTP specification is maintained by W3C (World-
wide Web Consortium) and available
at http://www.w3.org/standards/techs/http.
• There are currently two versions of HTTP, namely,
HTTP/1.0 and HTTP/1.1. The original version, HTTP/0.9
(1991), written by Tim Berners-Lee, is a simple protocol
for transferring raw data across the Internet. HTTP/1.0
(1996) (defined in RFC 1945), improved the protocol by
allowing MIME-like messages.
• HTTP/1.0 does not address the issues of proxies,
caching, persistent connection, virtual hosts, and range
download. These features were provided in HTTP/1.1
(1999) (defined in RFC 2616).
HTTP Request Methods
• HTTP protocol defines a set of request methods. A client can use one of
these request methods to send a request message to an HTTP server. The
methods are:
• GET: A client can use the GET request to get a web resource from the
server.
• HEAD: A client can use the HEAD request to get the header that a GET
request would have obtained. Since the header contains the last-modified
date of the data, this can be used to check against the local cache copy.
• POST: Used to post data up to the web server.
• PUT: Ask the server to store the data.
• DELETE: Ask the server to delete the data.
• TRACE: Ask the server to return a diagnostic trace of the actions it takes.
• OPTIONS: Ask the server to return the list of request methods it supports.
• CONNECT: Used to tell a proxy to make a connection to another host and
simply reply the content, without attempting to parse or cache it. This is
often used to make SSL connection through the proxy.
• Other extension methods.
References
• https://www.ntu.edu.sg/home/ehchua/progr
amming/webprogramming/HTTP_Basics.html