L'HyperText Transfer Protocol (HTTP) Tito Flagella Laboratorio Applicazioni Internet - Università di Pisa Tito Flagella - tito@link.it
Slide Title L'HyperText Transfer Protocol (HTTP) La Prima specifica pubblica HTTP/1.0, RFC IETF n. 1945 del 1996 http://tools.ietf.org/html/rfc1945 La Specifica più nota HTTP 1.1, RFC IETF n. 2616 del 1999 http://tools.ietf.org/html/rfc2616 L'Ultima Versione della Specifica HTTP 1.1, RFC IETF n. 7230-7235 del 2014 http://tools.ietf.org/html/rfc7230 Work in Progress HTTP 2 https://httpwg.github.io/ Tito Flagella - tito@link.it 2
Slide HTTP Title- RFC 7230 RFC 7230 - HTTP/1.1: Message Syntax and Routing - lowlevel message parsing and connection management RFC 7231 - HTTP/1.1: Semantics and Content - methods, status codes and headers RFC 7232 - HTTP/1.1: Conditional Requests - e.g., If- Modified-Since RFC 7233 - HTTP/1.1: Range Requests - getting partial content RFC 7234 - HTTP/1.1: Caching - browser and intermediary caches RFC 7235 - HTTP/1.1: Authentication - a framework for HTTP authentication Tito Flagella - tito@link.it 3
Slide HTTP Title- RFC 7230 L'annuncio di Mark Nottingham, chair del Working Group su HTTP di IETF https://www.mnot.net/blog/2014/06/07/rfc2616_is_dead So, in 2007, we started a new Working Group in the IETF called HTTPbis to improve the spec. Our charter was just to clarify, not to change it; we wanted to write the HTTP/1.1 specification down in a better way, not add new features or introduce a new version of the protocol. Along the way, we issued 26 draft versions, with over 2600 changsets, to address over 550 issues. Discussions of those issues brought in people from Open Source HTTP implementations like Apache, Curl, Squid, Traffic Server, HAProxy and Varnish, as well as people from companies that implement and use HTTP, from Microsoft and Apple to Yahoo! and Google. We generally stuck to clarifying the text, although in some places we tightened things up where there was a serious security or interoperability issue. For example, folding a header across multiple lines is now deprecated, and the message parsing rules have been tightened up considerably to avoid attacks like HTTP response splitting. Even where we just clarified, the changes are significant; for example, I edited the caching document, and ended up removing about ten pages of text, because 2616 said the same thing multiple times in slightly different ways! Tito Flagella - tito@link.it 4
Slide Caratteristiche Title Principali del Protocollo E' un protocollo di tipo request/response basato su TCP/IP Permette di indirizzare Risorse tramite Uniform Resource Identifiers (URIs), descritte nell'rfc 3986 Tito Flagella - tito@link.it 5
Slide Formato Title del Messaggio HTTP HTTP-message = start-line *( header-field CRLF ) CRLF Nelle richieste: [ message-body ] Start-line = method SP request-target SP HTTP-version CRLF Es: GET / HTTP/1.0 Nelle risposte: Start-line = HTTP-version SP status-code SP reason-phrase CRLF Es: HTTP/1.0 400 Bad Request Tito Flagella - tito@link.it 6
Slide Esempio Title di Transazione HTTP [tito@altrove-nb-eth ~]$ nc www.ibm.com 80 GET / HTTP/1.0 HOST: www.ibm.com HTTP/1.0 302 Moved Temporarily Server: AkamaiGHost Content-Length: 0 Location: http://www.ibm.com/us/en/ Date: Thu, 05 Mar 2015 12:21:52 GMT Connection: close Tito Flagella - tito@link.it 7
Slide Il protocollo Title HTTP: struttura di una richiesta una linea iniziale: tipo della richiesta (metodo), URI, protocol version Request headers (opzionali) Una linea vuota I dati della Richiesta (opzionale) 8
Slide Title Esempio di Richiesta GET /index.html HTTP/1.0 User-agent: Mozilla Accept: text/html, text/plain, image/jpeg 9
Slide Il protocollo Title HTTP: principali metodi GET: richiede il documento specificato nel URI HEAD: richiede solo l informazione header relativa al documento POST: richiede che il server accetti alcuni dati dal browser, come l input delle form html per un programma CGI PUT: sostituisce il contenuto di un documento del server con dati in arrivo dal client 10
Slide Header Titledella Richiesta Accept: i tipi di file che il browser può accettare Authorization: usato se il browser vuole autenticarsi con il server; contiene informazioni credenziali, come username e password. User-agent: il nome e la versione del browser Referer: la URL del documento che conteneva il link seguito dall utente. Host: l indirizzo IP e la porta della risorsa richiesta 11
Slide Dati Title della Richiesta In caso di POST o PUT, il cliente invierà i dati dopo gli header, seguiti da una linea vuota In caso di GET or HEAD non ci sono dati da spedire 12
Slide Title Risposta del Server La risposta include: versione del protocollo HTTP, codice di stato e reason phrase Header della Risposta Dati della Risposta 13
Slide Esempio Title di Risposta HTTP HTTP/1.0 200 OK Server: Netscape Enterprise Server/3.0 Content-type: text/html Content-length: 76 <HTML> <HEAD><TITLE>Hello World</Title></HEAD> <BODY>Hello World</BODY> </HTML> 14
Slide Codice Titledi Stato Lo status code è un intero di 3 cifre. La prima identifica una delle seguenti tipologie di risposta: 1xx indica un messaggio informativo interno al protocollo (es: 100 continue); 2xx indica il completamento con successo 3xx indica la ridirezione del client ad un altra risorsa 4xx indica un errore sul lato client 5xx indica un errore sul lato server Alcuni esempi di status code molto utilizzati: 200 OK 404 Not Found 301 Moved Permanently 302 Moved Temporarily 303 See Other 500 Server Error 15
Slide Esempi Titledi Stato HTTP 200: OK; operazione completata con successo 302: ridirezione a una nuova URL; la URL originale è stata spostata; non si tratta di un errore, i browser compatibili cercheranno la nuova pagina 304: usa una copia locale; i browser compatibili mandano una informazione su "last-modified" della copia della pagina in cache. Il server può rispondere con il codice 304 invece di mandare di nuovo la pagina 16
Slide Esempi Titledi Stato HTTP (2) 401: non autorizzato. L utente ha richiesto un documento ma non ha fornito uno username o una password validi 403: Vietato, l accesso alla URL è vietato 404: Non trovato; il documento non è disponibile sul server 500: Server error; si è verificato un errore interno del server 17
Slide Title Header della Risposta Contiene informazioni circa il server e i dati della risposta Gli header più comuni sono: Server: nome e versione del server web Date: la data corrente (Greenwich Mean Time) Last-modified: la data di ultima modifica del documento richiesto Expires: la data di scadenza del documento Content-length: dimensione in byte dei dati che seguono Content-type: il tipo MIME dei dati che seguono WWW-authenticate: usato durante l autenticazione, include informazioni necessarie per l accesso 18
Slide Dati Title relativi alla Risposta Il server manda una linea vuota dopo gli header Tutto ciò che segue costituisce i dati relativi alla risposta Può trattarsi di qualunque tipo di risorsa, come indicato dall'header Content-Type 19
Slide HTTP Title GET con Telnet telnet proxy 8080 Trying 10.114.87.2... Connected to proxy. Escape character is '^]'. GET http://www.google.it/index.html HTTP/1.1 HTTP/1.0 200 OK Cache-Control: private Content-Type: text/html; charset=iso-8859-1 Set-Cookie: PREF=ID=c0b [...] domain=.google.it Date: Mon, 18 Feb 2008 16:07:53 GMT Proxy-Connection: close <html>[...]
Slide HTTP Title GET con netcat [tito@altrove-nb-eth ~]$ nc www.ibm.com 80 GET / HTTP/1.0 HOST: www.ibm.com HTTP/1.0 302 Moved Temporarily Server: AkamaiGHost Content-Length: 0 Location: http://www.ibm.com/us/en/ Date: Thu, 05 Mar 2015 12:21:52 GMT Connection: close
Slide HTTP Title GET con curl curl --proxy proxy:8080 -v http://www.google.it/search?q=ciao *** REQUEST *** GET http://www.google.it/search?q=ciao HTTP/1.1 User-Agent: curl/7.16.4 (i386-redhat-linux-gnu) libcurl/7.16.4 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.8 Host: www.google.it Pragma: no-cache Accept: */* Proxy-Connection: Keep-Alive *** RESPONSE *** HTTP/1.0 403 Forbidden Content-Type: text/html Content-Length: 4362 Date: Mon, 18 Feb 2008 16:14:34 GMT HTTP/1.0 proxy connection set to keep alive! Proxy-Connection: keep-alive <html>[...]