2. HTTP
HTTP stands for Hypertext Transfer Protocol. It is an
TCP/IP based communication protocol which is used to
deliver virtually all files and other data, collectively
called resources, on the World Wide Web. These
resources could be HTML files, image files, query results,
or anything else.
A browser is works as an HTTP client because it sends
requests to an HTTP server which is called Web server.
The Web Server then sends responses back to the client.
The standard and default port for HTTP servers to listen
on is 80 but it can be changed to any other port like 8080
etc.
3. There are three important things
about HTTP of which you should be
aware:
HTTP is connectionless: After a request is made, the client disconnects
from the server and waits for a response. The server must re-establish the
connection after it process the request.
HTTP is media independent: Any type of data can be sent by HTTP as
long as both the client and server know how to handle the data content.
HTTP is stateless: This is a direct result of HTTP's being connectionless.
The server and client are aware of each other only during a request.
Afterwards, each forgets the other. For this reason neither the client nor the
browser can retain information between different request across the web
pages.
5. HTTP Message Structure
Like most network protocols, HTTP uses the client-server
model: An HTTP client opens a connection and sends a
request message to an HTTP server; the server then returns a
response message, usually containing the resource that was
requested. After delivering the response, the server closes the
connection.
The format of the request and response messages are
similar and will have following structure:
An initial line
Zero or more header lines
A blank line
An optional message body like file, query data or query
output.
6. Initial Line : Request
The
initial line is different for the request than for the response.
A request line has three parts, separated by spaces:
An HTTP Method Name
The local path of the requested resource.
The version of HTTP being used.
GET is the most common HTTP method. Other methods could
be POST, HEAD etc.
The path is the part of the URL after the host name. This path is
also called the request Uniform Resource Identifier (URI). A
URI is like a URL, but more general.
The
HTTP
version
always
takes
the
form
"HTTP/x.x", uppercase.
8. Initial Line : Response
The
initial response line, called the status line,
also has three parts separated by spaces:
The version of HTTP being used.
A response status code that gives the result of
the request.
An English reason phrase describing the status
code.
9. EXAMPLE of Initial Line :
Response
HTTP/1.0 200 OK
or
HTTP/1.0 404 Not Found
10. Header Lines
Header lines provide information about the request or response, or about
the object sent in the message body.
The header lines are in the usual text header format, which is: one line per
header, of the form "Header-Name: value". It's the same format used for
email and news postings.
A header line should end in.
The header name is not case-sensitive.
Any number of spaces or tabs may be between the ":" and the value.
Header lines beginning with space or tab are actually part of the previous
header line, folded into multiple lines for easy reading.
12. The Message Body
An HTTP message may have a body of data sent after the header
lines. In a response, this is where the requested resource is returned
to the client (the most common use of the message body), or
perhaps explanatory text if there's an error. In a request, this is
where user-entered data or uploaded files are sent to the server.
If an HTTP message includes a body, there are usually header lines
in the message that describe the body. In particular:
The Content-Type: Header gives the MIME-type (Multi-purpose
Internet Mail Extensions) of the data in the body, such as text/html
or image/gif.
The Content-Length: Header gives the number of bytes in the
body.
13. Request Methods
HTTP
defines methods (sometimes referred to
as verbs) to indicate the desired action to be
performed on the identified resource.
The HTTP/1.0 defined the GET, POST and
HEAD methods and the HTTP/1.1 added 5
new
methods:
OPTIONS, PUT, DELETE, TRACE and
CONNECT.
14. Above Methods are defined
as:
GET : Requests a representation of the specified resource. Requests using
GET should only retrieve data and should have no other effect. (This is
also true of some other HTTP methods). The W3C has published guidance
principles on this distinction, saying, "Web application design should be
informed by the above principles, but also by the relevant limitations." See
safe methods below.
HEAD : Asks for the response identical to the one that would correspond
to a GET request, but without the response body. This is useful for
retrieving meta-information written in response headers, without having to
transport the entire content.
POST :Requests that the server accept the entity enclosed in the request as
a new subordinate of the web resource identified by the URI. The data
posted might be, as examples, an annotation for existing resources; a
message for a bulletin board, newsgroup, mailing list, or comment thread;
a block of data that is the result of submitting a web form to a datahandling process; or an item to add to a database.
15. Methods (contd.)
PUT : Requests that the enclosed entity be stored under the supplied URI.
If the URI refers to an already existing resource, it is modified; if the URI
does not point to an existing resource, then the server can create the
resource with that URI.
DELETE :Deletes the specified resource.
TRACE : Echoes back the received request so that a client can see what
(if any) changes or additions have been made by intermediate servers.
OPTIONS : Returns the HTTP methods that the server supports for the
specified URL. This can be used to check the functionality of a web server
by requesting '*' instead of a specific resource.
CONNECT : Converts the request connection to a transparent TCP/IP
tunnel, usually to facilitate SSL-encrypted communication (HTTPS)
through an unencrypted HTTP proxy.
PATCH : Is used to apply partial modifications to a resource.
HTTP servers are required to implement at least the GET and HEAD
methods and, whenever possible, also the OPTIONS method.
17. 1xx : Information
Message:
100 Continue
Description:
Only a part of the request has been
received by the server, but as long as it
has not been rejected, the client should
continue with the request
101 Switching Protocols The server switches protocol
18. 2xx : Successful
Message:
Description:
200 OK
201 Created
The request is OK
The request is complete, and a new resource is
created
The request is accepted for processing, but the
processing is not complete
202 Accepted
203 Non-authoritative
Information
204 No Content
205 Reset Content
206 Partial Content
19. 5xx : Server Error
Message:
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not
Supported
Description:
The request was not completed. The server met
an unexpected condition
The request was not completed. The server did
not support the functionality required
The request was not completed. The server
received an invalid response from the upstream
server
The request was not completed. The server is
temporarily overloading or down
The gateway has timed out
The server does not support the "http protocol"
version