HTTP
From DocForge
HTTP is an abbreviation for HyperText Transport Protocol. It's the primary communications protocol used between web browsers and web servers, providing what's commonly known as the World Wide Web via the Internet.
Contents |
State [edit]
HTTP is a stateless protocol, meaning every request and response is independent of all others. The rendering of one web page may require many requests in addition to the main HTML, such as images and JavaScript. All of these requests are independent and will receive responses in an unknown order.
To preserve state, and know that multiple requests all come from the same source, cookies can be passed to the client and optionally preserved and resent in subsequent requests. Clients may, at any time, delete or expire cookies. Aside from cookies, unique values can be passed in the URL to maintain some sense of state.
HTTP Messages [edit]
As stated in the HTTP specification, HTTP headers are a set of lines, with the first line being either a request line, status line, or a header line. In HTTP 1.1, the header is terminated by a single blank line, and is followed by the message body (if applicable).
Client connection [edit]
Client connections normally start with the request line. The request line starts with a token indicating the type of request, followed by the URL or path to the target, and the version information. For example:
GET http://example.com/ HTTP/1.1
If the path is used instead of a URL or URI, the header must contain the host field:
GET / HTTP/1.1 Host:example.com
Standard requests include:
- OPTIONS
- GET
- HEAD
- POST
- PUT
- DELETE
- TRACE
- CONNECT
Headers for requests typically include:
- Accept
- Accept-Charset
- Accept-Encoding
- Accept-Language
- Authorization
- Expect
- From
- Host
- If-Match
- If-Modified-Since
- If-None-Match
- If-Range
- If-Unmodified-Since
- Max-Forwards
- Proxy-Authorization
- Range
- Referrer
- TE
- User-Agent
Server response [edit]
The server responds with a status line and associated headers. If there is a message content, it is separated by a blank line. It starts with the HTTP version code, the status code, and the status comment:
HTTP/1.1 200 Ok
Keep Alive [edit]
The first HTTP implementations opened and then closed a network socket connection for each request and response. This can hurt performance when many requests are required. To get around this issue browsers and servers implemented Keep-Alive, basically an unofficial extension to the HTTP 1.0 standard.
With HTTP 1.0, a browser which supported keep-alive would send "Connection: Keep-Alive" with the request header. A server also supporting it would send "Connection: Keep-Alive" with the response header. With both the browser and server in agreement the connection between the two is kept open. At an unspecified time the browser or server may close the connection.
With HTTP 1.1, all connections are kept alive by default, but without any guarantees. A connection may still close at any time. To intentionally request a connection be closed a header can contain "Connection: close".

