The following two headers try to give an idea how a HTTP request-response exchange might be executed.
Request
The HTTP protocol defines three parts for a HTTP request:
- One line identifying the request type and path (consisting of the three elements command, path and version)
- An optional set of RFC-822-style headers
- An optional data part
In the following sample request, the desired URI is http://rene.nyffenegger.ch/notes/development/web/HTTP.
So the client contacts the server (renenyffenegger.ch) and sends a header that might look like.
GET /notes/development/web/HTTP/header HTTP/1.1
host: renenyffenegger.ch
user-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0
accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
accept-language: de
accept-encoding: gzip, deflate
referer: www.google.com
accept-charset: *
x-forwarded-for: …
x-forwarded-host: …
x-forwarded-server: …
connection: close
In the request header, the first line is the request line that specifies the request method (in this example GET
), the URI and the protocol Version (HTTP/1.1
).
The request line is followed by header fields, each of which has a name that is separated from its value by a colon (:
).
The header extends to the first empty line.
Because it is a GET
request, there is no data part.
Response
The web server returns the requested resource along with a header.
The body of the resource is separated from the header by an empty line.
The first line of the response is a
status line that consists of
- HTTP Version (Format:
HTTP M/m
, M = Major number, m = minor number)
- A three-digit status code
- A character string that describes the status code
A potential response header from a
web server might be:
HTTP/1.0 200 OK
Date: Wed, 4 Mar 2020 21:18:13 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: …
<html>
…
</htm>