View on GitHub

Bearded-android-docs

HttpProtocol

Download this project as a .zip file Download this project as a tar.gz file

Created Saturday 09 November 2013

Basics

HTTP 1.0

HTTP 1.1

HTTP Transactions

HTTP messages look like this:

<initial line, different for request vs. response>
Header1: value1
Header2: value2
Header3: value3
etc...
[blank line here!!!]
<optional message body goes here, like file contents or query data;
 it can be many lines long, or even binary data $&*%@!^$@>

Notes: Blank lines should be CRLF!!! (but LF should also be handled properly)

Initial Line

Initial Request Line

The initial request line has three parts, each separated by a space:

  1. a method name (See +HttpMethods),
  2. the local path of the requested resource, and
  3. the HTTP version.

Example:

GET /path/to/file/index.html HTTP/1.0

Initial Response Line

The initial response line (aka the status line) has three parts, each separated by a space:

  1. the HTTP version,
  2. a response status code, and
  3. a reason (in "plain English") describing the status code.

Example:

HTTP/1.0 404 Not Found

Headers

Request Headers

For Net-politeness, using these optional headers is a good idea:

If you don't support persistent connections or if you know a request will be the last on its connection, then include

Example:

GET /path/file.html HTTP/1.1
Host: www.host1.com:80
[blank line here]

Response Headers

It's a good idea for servers to return these optional headers:

To tell the client the connection was closed use

A server might close the connection before all responses are sent, so a client must keep track of requests and resend them as needed. When resending, don't pipeline the requests until you know the connection is persistent.

Caching is an important improvement in HTTP 1.1, and can't work without timestamped responses. So, servers must timestamp every response with a Date: header containing the current time, in the form

Date: Fri, 31 Dec 1999 23:59:59 GMT


No backlinks to this page.
comments powered by Disqus