Brain Dump

HTTP

Tags
networking

An application layer protocol used for communication between web-browsers and web-servers.

HTTP defines several request methods including GET, POST, HEAD, PUT, DELETE, TRACE, etc. For a comprehensive list with descriptions for the purpose of each method see here.

Requests & Responses

A HTTP request is a plain-text query, shown below, with each line ending with carriage-return/line-feed. Requests are defined with the first line showing the request method, path and then the HTTP protocol version. The following lines specify HTTP headers (key value pairs) that describe the request. Then any data after a blank line is the request content.

GET / HTTP/2 Host: www.google.com user-agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0 accept: **/**

A HTTP response follows the same form as a request.

HTTP/2 200 date: Mon, 19 Jul 2021 22:38:11 GMT expires: -1 cache-control: private, max-age=0 content-type: text/html; charset=UTF-8 strict-transport-security: max-age=31536000 p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info." server: gws x-xss-protection: 0 x-frame-options: SAMEORIGIN set-cookie: CONSENT=PENDING+808; expires=Fri, 01-Jan-2038 00:00:00 GMT; path=/; domain=.google.com; Secure alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" accept-ranges: none vary: Accept-Encoding RESPONSE BODY

Some HTTP headers have special values. The set-cookie response header makes the client store some data and re-transmit it on any subsequent requests. The content-type and content-length headers describe the content of the request and response. Ordinarily for GET requests any method data (AKA params) are specified in the path itself (in the form described in URL). Alternatively one can place this data as the requests content and set the content-type field to application/x-www-form-urlencoded.

POST requests in particular transmit the request data in the content, sometimes as JSON, and is generally used for more secure communications.

[see page 18, GET vs POST]

GETPOST
Can be cached?YesNo
Can be bookmarked?YesNo
Tracked in browser historyYes (dangerous!)No
Have a maximum lengthYesNo

Links to this note