Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

HTTP Protocol

Also HTTP · Media Type · MIME Type

HTTP (Hypertext Transfer Protocol) is the text-based request–response protocol between browser (client) and web server, in which a request consists of a request line, headers and an optional body, and a response of a status line, headers (e.g. Content-Length, Content-Type), an empty line and the content.

Know these firstNetwork Socket

Formula#

Request format#

METHOD /path?param=value HTTP/1.1
Host: hostname:port
<more headers>

<body, only for e.g. POST>

/path?param=value is the part of the URL after http://<host>:<port>.

GET request example:

GET /search?query=bla HTTP/1.1
Host: localhost:8000

POST request example:

POST /submit HTTP/1.1
Host: localhost:8000
Content-Type: application/x-www-form-urlencoded
Content-Length: 9

query=bla

Response format#

HTTP/1.1 <status-code> <reason>
Content-Type: <media type>
Content-Length: <number of content bytes>

<content>

Example:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 18

{"result": "data"}

Status codes#

CodeMeaning
200OK
301Moved Permanently
400Bad Request
403Forbidden: the resource exists but may not be accessed by this client
404Not Found: the requested resource does not exist
500Internal Server Error

Media Types#

A media type (aka content type, formerly MIME type, MIME = Multipurpose Internet Mail Extensions) is a standard name for a type of content sent across the internet. The server declares it in the Content-Type header, optionally with the charset (text/html; charset=utf-8).

Media typeUsed for
text/htmlHTML pages
text/cssCSS stylesheets
text/plainplain text
application/javascriptJavaScript
application/jsonJSON data
image/jpegJPG image
image/x-iconICO image (notably favicon.ico)
application/x-www-form-urlencodedform POST data

Properties#

  • HTTP/1 demands that line breaks are \r\n; the recommendation is to accept a single \n, too.
  • Content-Length counts bytes of the content, not characters (Character Encoding).
  • HTTP is stateless: each request is independent.
  • GET parameters are in the URL (visible, bookmarkable, limited length) and must be URL-encoded. POST sends arbitrarily large data in the body along with the URL. There are many more request types and headers.
  • Connection reuse: browsers send Connection: keep-alive to reuse the connection; a server answering Connection: close forces a new connection per request (HTTP Server > Concurrency).
  • Cross-origin headers: Origin (request) and Access-Control-Allow-Origin (response) implement CORS (Same-Origin Policy).
  • APIs use the same format: the LLM and embedding APIs of Sheet 12 are POST requests with Content-Type: application/json, an Authorization: Bearer <key> header and a JSON body.
  • Debugging: browser development console (F12), tab Network, shows all requests and responses; curl -v prints them on the command line.

Example#

Sources#

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only