lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

HTTP.html (5805B)


      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      3 <html><head><link rel="stylesheet" type="text/css" href="sitewide.css"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 6.13.3 (455969)"/><meta name="altitude" content="-0.6550230383872986"/><meta name="author" content="Alex Balgavy"/><meta name="created" content="2018-01-10 2:33:25 PM +0000"/><meta name="latitude" content="52.33294868734879"/><meta name="longitude" content="4.865637733863039"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2018-01-10 2:48:06 PM +0000"/><title>HTTP</title></head><body><div>a request-response protocol</div><div>client is a user agent (browser), server is an application process running on a different computer</div><div><br/></div><div>URI: uniform resource identifier</div><div><ul><li>URN: uniform resource name</li><ul><li>unique name for resource (like a book’s ISBN)</li><li>relies on some authority to provide information</li></ul><li>URL: uniform resource locator</li><ul><li>location on the web</li><li>expect HTTP GET request to provide information about this resource</li></ul><li>a modern form is IRI (international resource identifier) which can also include unicode characters, not just ASCII</li></ul><div><br/></div></div><div>URLs:</div><div><font color="#ff2600">http://www.example.org</font>:<font color="#ff9300">5678</font><font color="#ff40ff">/a/b.txt</font>?<font color="#0433ff">tc=win&amp;r=10</font><font color="#942192">#para5</font></div><div><ul><li>contain</li><ul><li>authority</li><ul><li><span style="color: rgb(255, 38, 0);">host (FQDN, fully qualified domain name)</span></li><li><span style="color: rgb(255, 147, 0);">port</span></li></ul><li>request-URI</li><ul><li><span style="color: rgb(255, 64, 255);">path</span></li><li><span style="color: rgb(4, 51, 255);">query</span></li></ul><li><span style="color: rgb(148, 33, 146);">fragment</span></li></ul><li>browser connects to authority over TCP</li><li>request-URI included in start line (/ is default)</li><li>fragment is not sent to server, used to scroll user’s view</li></ul><div><br/></div></div><div>Content negotiation</div><div><ul><li>multiple representations via the same URI</li><li>client-server negotiation determines what shows up</li></ul><div><br/></div></div><div>Request methods</div><div><ul><li>GET: get documents, no body in request</li><li>POST: e.g. when you click submit, form information is included in the boyd</li><li>HEAD: requests only the header fields to be returned</li></ul><div><br/></div></div><div>Request example:</div><div><font face="Courier New">GET /test.html HTTP/1.1</font></div><div><font face="Courier New">HOST: <a href="http://www.example.org">www.example.org</a></font></div><div>…</div><div><br/></div><div><font face="Helvetica Neue">Response example:</font></div><div><font face="Courier New">HTTP/1.1 200 OK</font></div><div><font face="Courier New">Date: &lt;timestamp&gt;</font></div><div><br/></div><div><font face="Helvetica Neue">Header fields are included in the requests, like:</font></div><div><ul><li><span style="font-family: &quot;Helvetica Neue&quot;;">user agent</span></li><li><span style="font-family: &quot;Helvetica Neue&quot;;">referrer</span></li><li><span style="font-family: &quot;Helvetica Neue&quot;;">content type</span></li><li><span style="font-family: &quot;Helvetica Neue&quot;;">acceptable MIME types (data types like text/html, image/png, vide/mp4)</span><br/></li><li><font face="Helvetica Neue">character encoding (most popular being UTF-8 encoding of unicode)</font></li></ul></div><div><ul/><div><br/></div></div><div><font face="Helvetica Neue">HTTP response codes:</font></div><div><ul><li><font face="Helvetica Neue">three-digit number</font></li><li><font face="Helvetica Neue">first digit is the class</font></li><ul><li><font face="Helvetica Neue">1: information</font></li><li><font face="Helvetica Neue">2: success</font></li><li><font face="Helvetica Neue">3: redirect</font></li><li><font face="Helvetica Neue">4: client fucked up</font></li><li><font face="Helvetica Neue">5: server fucked up</font></li></ul><li><font face="Helvetica Neue">other two digits are extra information</font></li></ul><div><font face="Helvetica Neue"><br/></font></div></div><div><font face="Helvetica Neue">HTTP servers:</font></div><div><ul><li><font face="Helvetica Neue">initially, there weren’t that many, mostly FTP in the 90s</font></li><li><font face="Helvetica Neue">then, NCSA made httpd for free, and promptly fucked off to work on Netscape (stopping all support)</font></li><li><font face="Helvetica Neue">so developers started making patches, and turned it into “a patchy server”…the Apache server</font></li><li><font face="Helvetica Neue">a main loop for a server looks like so:</font></li></ul></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font face="Courier New">while forever</font></div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font face="Courier New">listen on TCP port 80</font></div><div><font face="Courier New">read request</font></div><div><font face="Courier New">send response</font></div></blockquote></blockquote><font face="Helvetica Neue"><ul><li>the server doesn’t know its own hostname, because host names may be on the same machine (virtual hosts) and different responses may be needed for different hostnames</li><li>the server uses a config file to determine where “/“ is (the document root)</li></ul></font><div><br/></div></body></html>