Slide 1

Slide 1 text

HTTP

Slide 2

Slide 2 text

HyperText Transfer Protocol

Slide 3

Slide 3 text

HTTP request GET /index.1.de.html HTTP/1.1 Host: www.example.com

Slide 4

Slide 4 text

HTTP request GET / HTTP/1.1 Host: www.example.com Connection: keep-alive Cache-Control: no-cache Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Pragma: no-cache User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36 Accept-Encoding: gzip,deflate,sdch Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4 Cookie: sid=t73fuqi322d115fdr8tt1fsf30

Slide 5

Slide 5 text

HTTP response HTTP/1.1 200 OK Date: Thu, 20 Feb 2014 14:42:03 GMT Server: Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 mod_ssl/2.2.22 OpenSSL/1.0.1 X-Powered-By: PHP/5.3.10-1ubuntu3.9 P3P: CP="NOI NID ADMa OUR IND UNI COM NAV" Set-Cookie: sid=t73fuqi322d115fdr8tt1fsf30; path=/; HttpOnly Expires: Sun, 22 Dec 2013 14:42:03 GMT Cache-Control: no-store, no-cache, must-revalidate, no-transform Last-Modified: Thu, 20 Feb 2014 14:42:03 GMT X-Generator: papaya CMS X-Papaya-Cache: no Content-Encoding: gzip X-Papaya-Gzip: yes Content-Length: 6315 Keep-Alive: timeout=5, max=95 Connection: Keep-Alive Content-Type: text/html; charset=utf-8

Slide 6

Slide 6 text

HTTP-Methoden ● GET ● POST ● PUT ● DELETE ● HEAD

Slide 7

Slide 7 text

HTTP status codes

Slide 8

Slide 8 text

Exkurs: Caches

Slide 9

Slide 9 text

Cache-Arten ● Browser-Cache ● Proxy Cache ● Gateway Cache / Reverse Proxy – Self-hosted (Varnish, …) – Kommerziell / CDN (Cloudflare, Akamai & co.)

Slide 10

Slide 10 text

Cache-relevante HTTP-Header ● Expires ● Cache-Control ● ETag ● Last-Modified ● If-Modified-Since ● If-None-Match ● Vary ● Age ● Set-Cookie

Slide 11

Slide 11 text

Expires Expires: Sun, 22 Dec 2013 14:42:03 GMT ● HTTP/1.0 ● Ablaufdatum des Inhalts (Zeitzone GMT!) ● Nützlich für Caching statischer Ressourcen

Slide 12

Slide 12 text

Cache-Control Cache-Control: no-cache, must-revalidate ● HTTP/1.1 ● Wesentlich feinere Kontrolle über den Cache ● Optionen: – max-age – s-maxage – public – private

Slide 13

Slide 13 text

Cache-Control Cache-Control: no-cache, must-revalidate ● HTTP/1.1 ● Wesentlich feinere Kontrolle über den Cache ● Optionen (2): – no-cache – no-store – must-revalidate – proxy-revalidate

Slide 14

Slide 14 text

ETag ETag: [W/]"some-random-value" ● HTTP/1.1 ● Identifiziert eine Version einer Ressource eindeutig ● Starker ETag: Garantiert identische Ressource ● Schwacher ETag (W/): Garantiert äquivalente Ressource ● Bei statischen Ressourcen abschalten

Slide 15

Slide 15 text

Last-Modified Last-Modified: Thu, 20 Feb 2014 14:42:03 GMT ● Letztes Änderungsdatum der Ressource

Slide 16

Slide 16 text

If-Modified-Since If-Modified-Since: Wed, 01 Sep 2004 13:24:52 GMT ● Request-Header ● Nur ausliefern, wenn neuere Version vorhanden ● Sonst Status 304

Slide 17

Slide 17 text

If-None-Match If-None-Match: "some-random-value" ● Request-Header ● Abfrage, ob Version mit diesem ETag vorhanden ● Wenn ja: Status 304

Slide 18

Slide 18 text

Vary Vary: Cookie,Accept,Accept-Encoding ● Information an Caches: Antwort unterscheidet sich je nach Wert der angegebenen Request- Header! ● Bspw. wichtig im Umgang mit schlecht konfigurierten Corporate Proxies

Slide 19

Slide 19 text

Age Age: 30 ● Gibt das Alter der Ressource in Sekunden an ● Caches rechnen: request timestamp – now – Age + max-age > 0? ● Wird auch von Caches selbst angegeben

Slide 20

Slide 20 text

Set-Cookie Set-Cookie: name=somevalue; Secure ● Inhalt, der Cookies enthält, ist uncached! ● Aber: Cookies sind nützlich, um mehrere Versionen einer Ressource im Reverse-Proxy zu cachen.

Slide 21

Slide 21 text

POST ● POST bedeutet: Es wird eine Ressource verändert. ● Antworten auf POST-Requests werden nicht gecached. ● POST also nur da verwenden, wo es nötig ist.

Slide 22

Slide 22 text

Ressourcen ● Wikipedia: „Liste der HTTP-Headerfelder“ ● Caching Tutorial for web authors and webmasters: http://www.mnot.net/cache_docs/ ● HTTP – The Varnish Cookbook: https://www.varnish-software.com/static/book/HTTP.html ● YSlow: Best practices for speeding up your website: http://developer.yahoo.com/performance/rules.html

Slide 23

Slide 23 text

Noch Fragen?