SlideShare a Scribd company logo
Argomenti 
•Architetture web 
•Livelli, server, standard, protocolli 
•HTTP (Hypertext Transfer Protocol) 
Percorso 7 
Architetture Web 
2
Evoluzione delle architetture web 
Percorso 7 
Architetture Web 
3 
http://www.evolutionoftheweb.com
Architettura ad N livelli 
Browser 
Internet infrastructure 
Web Server 
Application Server 
Database Server 
•Ciascun livello ha un ruolo ben definito 
•Uno o più “server” implementano ciascun livello 
•I server possono condividere lo stesso hardware 
•La comunicazione tra i livelli avviene attraverso meccanismi di rete 
Percorso 7 
Architetture Web 
4 
3rd party services 
Client
Architettura generale 
Percorso 7 Architetture Web 5 
Client 
Internet Server(s) 
• Storicamente, un 
browser web 
• Ma anche: 
• Applicazione Mobile 
• Applicazione 
Desktop 
• Altra applicazione 
server
Componenti 
•Una o più connessioni ad Internet (attraverso un ISP) 
•Uno o più server che implementino ciascun livello dell’architettura 
•Una o più reti fisiche per interconnettere I server 
•Uno o più apparati di rete (router, firewall, switch) per implementare le politiche di comunicazione e di sicurezza. 
Percorso 7 
Architetture Web 
6
Definitione 
•“Server” si può definire come 
–Definizione logica: Un processo, in esecuzione su un computer host, che fornisce informazione ad un client al ricevimento di una richiesta. 
–Definizione fisica: Un computer host, collegato in rete, che contiene delle informazioni (es. Siti web) e che risponde alle richieste per tali informazioni 
Percorso 7 
Architetture Web 
7
Server Web 
•Gestisce il protocollo HTTP (riceve le richieste e fornisce le risposte) 
–Riceve richieste dai client 
–Legge contenuti e pagine statiche dal filesystem 
–Attiva l’application server per le pagine dimaniche e per la generazione di contenuti dinamici server-side 
–Fornisce al client un file (HTML o altro) come risposta 
•Una connessione HTTP per ciascuna richiesta 
•Multi-process, Multi-threaded, Process pool 
Percorso 7 
Architetture Web 
8
Esempio 
Percorso 7 Architetture Web 9 
Client 
Web 
server 
Internet 
URL 
http request 
HTML 
files 
display http response 
page 
TCP/IP 
path 
browser server file system 
HTML 
send
Standard adottati 
•URL (uniform resource locator) per identificare le pagine web 
•HTML (hyper text markup language) per costruire le pagine web 
•GIF (graphics interchange format), PNG (portable network graphics), JPEG, … per le immagini 
•HTTP (hyper text transfer protocol) per l’interazione tra client e server 
•TCP/IP (transmission control protocol over internet protocol) per il trasferimento di dati 
Percorso 7 
Architetture Web 
10
URL 
Percorso 7 
Architetture Web 
11 
http://elite.polito.it/~corno/index.html 
DNS 
130.192.5.26 
TCP 
Contact server 
File system 
URI Rewriting 
HTML file contents 
/home/corno/public_html/index.html 
RFC 2396 
http://www.w3.org/Addressing/
URI Basics 
•http://www.sadev.co.za/users/1/contact 
•http://www.sadev.co.za?user=1&action=contact 
•http://rob:pass@bbd.co.za:8044 
•https://bbd.co.za/index.html#about 
Percorso 7 
Architetture Web 
12 
Scheme 
Scheme 
Scheme 
Scheme 
Hostname 
Hostname 
Hostname 
Hostname 
Query 
Query 
Query 
Port 
Fragment 
Userinfo
Protocollo HTTP 
Percorso 7 
Architetture Web 
13 
GET /~corno/index.html HTTP/1.0 
Accept: text/html 
Accept: image/gif 
User-Agent: Firefox/Windows Browser 18.3 
HTTP/1.0 200 OK 
Date: Monday, 01-Jan-2001 00:00:00 GMT 
Server: Apache 1.3.0 
MIME-Version: 1.0 
Last-Modified: 31-Dec-2000 
Content-type: text/html 
Content-length: 3021 
<HTML> . . . 
RFC 2616, RFC 2617 http://www.w3.org/Protocols
Misure di prestazione 
•Latenza: tempo necessario a fornire una risposta http contenente una pagina di 0 byte. Rappresenta il costo di elaborazione fisso di ciascuna pagina. 
–Misurata in: http/s o s/http 
•Throughput: massima velocità a cui una pagna di lunghezza infinita può essere inviata. 
–Misurata in: byte/s, MB/s 
Percorso 7 
Architetture Web 
14
Tempo di risposta 
•T = Latency + ResponseBytes / Throughput 
•Equazione valida se: 
–Gli altri elementi architetturali (I/O, reti, ...) non sono sovraccarichi 
–Il server web non ha ancora raggiunto il massimo carico sopprtabile 
•Esempio: 
–Latency: 0,1s 
–ResponseBytes : 100kBytes 
–Throughput: 800kBytes/s 
–T= 0,1s+ 100KBytes / 800KBytes/s =0,225s 
Percorso 7 
Architetture Web 
15
Transazione web statica 
Percorso 7 
Architetture Web 
16 
Browser 
Web 
server 
Disk 
access 
t0 
t1 
t2 
t3 
t4 
t6 
t7 
t8 
t9 
t5 
t’0 
t’1 
total response time 
server response time 
user think time 
network transfer time
General Architecture 
Percorso 7 
Architetture Web 
17 
internet 
Web application 
(PHP, JSP, …) 
Browser 
Display 
Mouse/ 
Keyboard 
Web server (Apache, IIS) 
HTML file 
Image file 
Layout engine 
IMG 
IMG 
HTM 
HTM
The most adopted web servers 
Percorso 7 
Architetture Web 
18 
Source: http://news.netcraft.com/ 
http://news.netcraft.com/archives/2014/03/03/march-2014-web-server-survey.html
Application server 
•Generazione delle pagine e dei contenuti dinamici 
•Gestisce la logica operativa e funzionale (business logic) del sito 
•Livello intermedio tra il front-end (web) ed il back- end (database) 
•Implementa i meccanismi di sessione (gestione cookie) 
•Realizzabile con diverse tecnologie, architetture e linguaggi di programmazione 
Percorso 7 
Architetture Web 
19
Transazione web dinamica 
Percorso 7 Architetture Web 20 
Client 
Web 
server 
Internet 
URL 
& data 
http request 
with data 
display http response 
page 
TCP/IP 
com-mand 
browser server application 
HTML 
send 
Application 
para-meters 
logic
Standard adottati 
•Estensioni HTTP per inviare dati 
–HTTP-POST 
–URL-encoding in HTTP-GET requests 
•Tecnologie per integrare codice applicativo nel server web 
–java servlets 
–ASP (active server pages), JSP, PHP, PERL, Python as new languages for application development 
•Cookie per gestire lo stato di una sessione 
Percorso 7 
Architetture Web 
21
URL (HTTP GET) 
Percorso 7 
Architetture Web 
22 
http://www.cad.polito.it/pap/pap.pl?author=Corno 
CPU 
Application 
HTML 
Parameters 
Disk 
Libraries
Transazione web dinamica 
Percorso 7 
Architetture Web 
23 
Browser 
Web 
server 
Application 
server 
t0 
t1 
t2 
t3 
t5 
t6 
t7 
t8 
t9 
t4 
total response time 
application time 
total server time 
t’0 
t’1
Server database 
•Memorizza i dati su cui lavora l’application server 
•Esegue le interrogazioni (query) richieste dall’application server: 
–Aggiorna i dati memorizzati 
–Inserisce nuovi dati 
–Restituisce i risultati delle ricerche 
•Le query più complesse o più frequenti possono essere implementate all’interno del database, per mezzo di «stored procedure» e/o query parametriche. 
Percorso 7 
Architetture Web 
24
Esempio 
Percorso 7 Architetture Web 25 
Client 
Web 
server 
Internet 
URL 
& data 
http 
req 
http 
resp 
display 
page 
TCP/IP 
com-mand 
browser server application 
HTML 
send 
Application 
para-meters 
database 
data 
Database 
query
Standard adottati 
•Basi di dati relazionali (RDMBS) 
•SQL (structured query language) 
•JDBC/ODBC per accedere alle basi dati 
Percorso 7 
Architetture Web 
26
Database server 
•Queries are almost always in SQL 
–SELECT * FROM table; 
–.... 
•Often adopts the relational database model 
–Other models can be used 
•Object model 
•Triple model 
•The most advanced/complete solutions are called Transaction servers 
Percorso 7 
Architetture Web 
27
Database-driven transaction 
Percorso 7 
Architetture Web 
28 
Browser 
Web server 
Application 
server 
Database 
server 
t0 
t1 
t2 
t3 
t5 
t6 
t7 
t8 
t9 
t4 
t’0 
t’1 
total response time 
application time 
total server time 
database time
Esempio (PHP) 
•<?php 
•$query = “SELECT doc_id FROM key_doc_index, keywords WHERE key_doc_index.key_id = keywords.id AND keywords.key = $_REQUEST[“query”];”; 
•$rowset = mysql_query($query); 
•while($row = mysql_fetch_row($rowset)) 
•{ 
•//elaborate data 
•} 
•?> 
Percorso 7 
Architetture Web 
29 
The application composes the query 
The query is sent to the db-server and a rowset containing the results is returned 
The application elaborates the data
General Architecture 
Percorso 7 
Architetture Web 
30 
internet 
Web application 
(ASP, PHP, JSP, …) 
Browser 
Display 
Mouse/ 
Keyboard 
Web server (Apache, IIS) 
HTML file 
Image file 
Layout engine 
IMG 
IMG 
HTM 
HTM 
Database 
Database Server DBMS 
SQL
Interazione lato client 
•Gli standard W3C regolano l’interazione client- server, ma gli utenti vogliono maggiore interazione sul client 
•Nuovi standard e linguaggi permettono dei comportamenti dinamici all’interno di una pagina caricata, senza coinvolgere il server 
Percorso 7 
Architetture Web 
31
General Architecture 
Percorso 7 
Architetture Web 
32 
internet 
Web application (ASP, PHP, JSP, …) 
Browser 
Display 
Mouse/ 
Keyboard 
Web server 
(Apache, IIS) 
HTML file 
Image file 
Layout engine 
IMG 
IMG 
HTM 
HTM 
Database 
Database Server DBMS 
SQL 
Javascript engine 
JS 
CSS 
HTM 
DOM 
CSS stylesheets 
Javascript 
JS 
CSS
Web 2.0 
•Web applications support social interaction models 
•Peer exchange and user-contributed content instead of rigid publisher/reader pattern 
–Online communities 
•Rich, dynamic, interactive user interfaces 
•Integration of contents across web sites (mashups) 
Percorso 7 
Architetture Web 
33
Rich-Client Asynchronous Transactions 
Percorso 7 Architetture Web 34 
Client 
Web 
server 
Internet 
URL 
http 
display http 
page 
TCP/IP 
com-mand 
browser server application 
HTML 
send 
Application 
para-meters 
database 
data 
Database 
query 
Client-side 
Application 
runtime 
events 
DOM 
http 
XML/JSON
Adopted standards 
•Dynamic HTML: DOM, Javascript, CSS 
–JavaScript, Flash to handle a runtime environment on the browser 
–DOM (XHTML Document Object Model) to allow on-the fly modification of the web page 
–CSS 2.1 to modify attribute and handle objects 
•AJAX: Asynchronous Javascript and XML 
–XMLHttpRequest for asynchronous communication to the server 
–Data transfer formats: JSON, XML, RDF, RSS, Atom, FOAF, ... 
•Mash-up technology 
Percorso 7 
Architetture Web 
35
Rich-client transaction 
Percorso 7 
Architetture Web 
36 
Browser 
Web server 
Application 
server 
Database server 
t9 
t0 
t1 
t2 
t3 
t5 
t6 
t7 
t8 
t4 
t’0 
t’1 
Runtime
General Architecture 
Percorso 7 
Architetture Web 
37 
internet 
Web application 
(ASP, PHP, JSP, …) 
Browser 
Display 
Mouse/ 
Keyboard 
Web server (Apache, IIS) 
HTML file 
Image file 
Layout engine 
IMG 
IMG 
HTM 
HTM 
Database 
Database Server DBMS 
SQL 
Javascript engine 
JS 
CSS 
HTM 
DOM 
CSS stylesheets 
Javascript 
JS 
CSS 
Data 
XML, JSON
Architettura generale del web 
Percorso 7 
Architetture Web 
38 
internet 
Database 
Applicazione web (ASP, PHP, JSP, …) 
Browser 
Schermo 
Mouse/ 
Tastiera 
Server web 
(Apache, IIS) 
Server database DBMS 
File HTML 
File 
Immagini 
Fogli di stile CSS 
Javascript 
Motore Layout 
Motore Javascript 
IMG 
JS 
JS 
IMG 
CSS 
CSS 
HTM 
HTM 
HTM 
SQL 
DOM 
Dati 
XML, 
JSON 
XML, 
JSON 
Questo è sufficiente per il sito di ricette di cucina della nonna… 
… ma nella realtà il mondo enterprise è molto più complesso
Distributed transactions 
Percorso 7 Architetture Web 39 
Client 
Web 
server 
Internet Application 
Web 
server 
Internet 
Application 
XML/JSON
Requisiti del mondo “reale”… 
•The users 
•Functionality 
•Flexibility 
•Portability 
•Reliability 
•Security 
•Integrity 
•Maintenance 
•Performance 
•Scalability 
•Costs 
•Maintenance 
•Development times 
•Interactions with existing systems 
•Interactions with the “physical” world 
Percorso 7 
Architetture Web 
40
Il problema delle sessioni 
•Il protocollo HTTP è “senza memoria” (stateless) 
•Ogni richiesta è indipendente dalle altre, e non può “ricordare” il percorso precedente di un utente 
•Le variabili di input di ogni pagina possono dipendere solamente dai FORM nella pagina precedente 
•Gli utenti, invece, vorrebbero avere l’impressione di una navigazione continua, in cui una scelta compiuta in una pagina venga “ricordata” in tutte le pagine successive. 
•È necessario costruire una astrazione di una sessione di navigazione 
•Sessione = sequenza di pagine, visitata sullo stesso sito dallo stesso utente con lo stesso browser nella stessa seduta di navigazione, che presentino una consequenzialità logica 
Percorso 7 
Architetture Web 
41
login: 
password: 
fulvio 
**** 
Login accettato. Benvenuto, fulvio Controlla la posta! 
home.html 
login.php 
VAI 
Utente attivo: fulvio La tua posta: XXX 
posta.php 
login.php?user=fulvio&pass=xyzq 
??? 
Esempio 
•L’utente inserisce i propri username e password sulla prima pagina che visita 
•La pagina successiva sarà necessariamente una pagina dinamica che “valida” il login 
•Tutte le pagine successive dovranno conoscere il nome dell’utente 
Percorso 7 
Architetture Web 
42
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
<title>Pagina di login</title> 
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> 
</head> 
<body> 
<h1>Inserisci i tuoi dati</h1> 
<form method="GET" action="login.php"> 
Nome utente: <input type="text" name="user" /> <br /> 
Password: <input type="password" name="pass" /> <br /> 
<input type="submit" /> 
</form> 
</body> 
</html> 
Percorso 7 
Architetture Web 
43
Le soluzioni possibili 
•URL rewriting 
•Variabili nascoste nei FORM 
•Cookie 
•Session management 
Percorso 7 
Architetture Web 
44
Cookie 
•Un cookie è una (piccola) quantità di informazione che il server può memorizzare sul browser 
•Nella risposta http il server aggiunge un comando di intestazione “set cookie” 
•Il browser si impegna a restituire al server il cookie ad ogni nuova richiesta http che farà 
•Il cookie è composto da 
–Nome 
–Valore 
–Scadenza 
–Dominio 
•Esempio: Nome: “user”, valore: “fulvio”, scadenza: “1200”, dominio: “miosito.it” 
Percorso 7 
Architetture Web 
45
Cookie 
•Quando login.php valida la password, può settare un cookie sul browser 
•La pagina posta.php può leggere il cookie, che il server riceverà nuovamente dal browser 
•Accesso ai cookie da PHP: 
–Per scrivere: setcookie("nome", "valore") 
•bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]] ) 
•Deve essere chiamata prima di ogni contenuto HTML (anche spazi!) 
–Per leggere: $_COOKIE["nome"] 
–Per verificare: if( isset($_COOKIE["nome"]) ) ... 
–Per cancellare: setcookie("nome", "") 
Percorso 7 
Architetture Web 
46
Pratica consigliata 
•Tra le alternative viste, la più conveniente è l’utilizzo dei cookie, poiché: 
–È sufficiente fare una sola setcookie all’inizio 
–È possibile settare più cookie relative a diverse variabili 
–Non occorre modificare né i link esistenti né i form esistenti 
•Svantaggi: 
–Non è possibile memorizzare informazioni voluminose 
–Non è “educato” memorizzare molti cookie diversi 
–Non è consigliabile fidarsi dei dati memorizzati sul browser dell’utente 
–È possibile che il browser rifiuti di restituire i cookie memorizzati 
Percorso 7 
Architetture Web 
47
Session management 
•È possibile memorizzare più variabili con un solo cookie (breve): 
•Il cookie memorizza un “numero magico”, diverso per ogni nuova sessione 
•nome="session" value="123456" 
•Il server memorizza, da qualche parte, le variabili di sessione associate al numero magico 
•Session=123456  "user" = "fulvio" 
•Può essere memorizzato nella memoria del web server, oppure in un file privato del server (es. session.123456.variables), oppure in una tabella di database (Session, Name, Value) 
•Ad ogni nuova pagina, il cookie ricevuto può “sbloccare” le variabili opportune e renderle disponibili nella pagina. 
Percorso 7 
Architetture Web 
48
Session management in PHP 
•Attivare la sessione: 
–session_start() 
•Nessun parametro, va chiamata prima di ogni altra cosa 
•Crea una nuova sessione o recupera quella esistente 
•Crea un cookie di nome simile a PHPSESSID123456 
–Il vettore $_SESSION["nome"] può essere usato per memorizzare le variabili associate con la sessione: 
•$_SESSION["user"] = "fulvio" 
•echo $_SESSION["user"] 
•If ( isset( $_SESSION["user"] ) ) ... 
•Chiudere la sessione: 
–Scade automaticamente dopo 20-30 minuti 
–Scade automaticamente chiudendo il browser 
–Può essere “resettata” con session_destroy() 
Percorso 7 
Architetture Web 
49
<?php 
session_start() ; 
$user = $_REQUEST["user"] ; 
$pass = $_REQUEST["pass"] ; 
if($user == "fulvio" && $pass == "xyz") 
{ 
// login OK 
$_SESSION["user"] = $user ; 
$login = 1 ; 
} 
else 
{ 
// login errato 
$login = 0 ; 
} 
?> 
<html> <head> <title>Controllo login</title> </head> <body> <?php if($login == 1) { echo "<p>Benvenuto, $user</p>n"; echo "<p>Controlla la tua <a href="posta.php">posta</a></p>n" ; } else { echo "<p>ERRORE: login non valido, <a href="home.html">riprova</a></p>n" ; } //echo "<p>Password: $pass</p>n" ; ?> </body> </html> 
Percorso 7 
Architetture Web 
50
Esempio: posta.php 
<?php 
session_start() ; 
?> 
<html> 
<head> 
<title>La tua posta</title> 
</head> 
<body> 
<? 
if(isset($_SESSION["user"])) 
{ 
$user = $_SESSION["user"] ; 
echo "<p>Ecco la tua posta, $user</p>n" ; 
/* stampa la posta... */ 
} 
else 
{ 
echo "<p>ERRORE: devi prima fare il <a href="home.html">login</a></p>n" ; 
} 
?> 
</body> 
Percorso 7 
Architetture Web 
51
Percorso 7 
Architetture Web 
52
What is HTTP? 
•HTTP stands for Hypertext Transfer Protocol 
•It is the network protocol used to delivery virtually all data over the WWW: 
–Images 
–HTML files 
–Query results 
–Etc. 
•HTTP takes places over TCP/IP connections 
Percorso 7 
Architetture Web 
53 
http://www.ietf.org/rfc/rfc2616.txt
HTTP clients and servers 
•A browser is an HTTP client because it sends requests to an HTTP server, which then sends responses back to the client. 
•The standard port for HTTP servers to listen on is 80, though they can use any port. 
Percorso 7 
Architetture Web 
54 
Http - request 
Http - response
HTTP messages 
•The format of the request and response messages are similar (English-oriented). They consist of: 
–An initial line 
–Zero or more header lines 
–A blank line (CRLF) 
–An optional message body 
Percorso 7 
Architetture Web 
55 
Initial line header1: value1 header2: value2 header3: value3 message body...
Header Example 
•HEAD /index.html HTTP/1.1 
•Host: www.example.com 
Percorso 7 
Architetture Web 
56 
HTTP/1.1 200 OK 
Date: Mon, 23 May 2005 22:38:34 GMT 
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux) 
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT 
Etag: "3f80f-1b6-3e1cb03b" 
Accept-Ranges: bytes 
Content-Length: 438 
Connection: close 
Content-Type: text/html; charset=UTF-8 
Request 
Response
HTTP Basics 
•HTTP is not HTML 
•HTTP is stateless 
Percorso 7 
Architetture Web 
57 
HTTP 
(Request, 
Response) 
Header 
Body 
URI 
Method 
Status Code 
http://www.sadev.co.za 
GET 
200 
text 
Content Type 
text/plain
HTTP msg – initial line 
•The initial line is different for the request and the response. 
•A request initial line has three parts separated by white spaces: 
–A method name 
–The local path of the requested resource 
–The version of the HTTP being used 
•GET /path/to/file/index.html HTTP/1.0 
Percorso 7 
Architetture Web 
58
HTTP msg – initial line 
–The method name is always in upper case. 
–There are several methods for a HTTP request 
•GET (most commonly used) 
•POST (used for sending form data) 
•HEAD 
•... 
–The path is the part of the URL after the host name 
•http://www.tryme.com/examples/example1.html 
Percorso 7 
Architetture Web 
59
HTTP Method Basics 
HEAD 
Gets just the HTTP header 
GET 
Gets HTTP head & body 
POST 
Submits data in the body to the server 
PUT 
Uploads a resource 
DELETE 
Deletes a resource 
TRACE 
Echo’s back the request 
OPTIONS 
Gets a list of supported methods 
CONNECT 
Converts to a TCP/IP tunnel for HTTPS 
PATCH 
Apply partial modifications to a resource 
Percorso 7 
Architetture Web 
60
HTTP msg – initial line 
–The HTTP version is always in the form 
•HTTP/x.x (uppercase) 
–The versions currently in use are: 
•HTTP/1.0 
•HTTP/1.1 
Percorso 7 
Architetture Web 
61
HTTP msg – initial line 
•The response initial line is usually called status line and has also 3 parts separated by spaces: 
–The HTTP version 
–The response status code 
–An English phrase describing the status code 
•Example: 
–HTTP/1.0 200 OK 
–HTTP/1.0 404 Not Found 
Percorso 7 
Architetture Web 
62
Response Status Codes 
•1xx – Informational 
•2xx – Success 
•3xx – Redirection 
•4xx – Client Error 
•5xx – Server Error 
Percorso 7 
Architetture Web 
63
Response Status Codes 
•1xx – Informational 
•2xx – Success 
•3xx – Redirection 
•4xx – Client Error 
•5xx – Server Error 
•100 = Continue 
•102 = Processing 
•200 = OK 
•201 = Created 
•204 = No Content 
•206 = Partial Content 
•301 = Moved Permanently 
•302 = Found (Moved Temp) 
•307 = Temp Redirect 
•400 = Bad Request 
•401 = Unauthorised 
•402 = Payment Required 
•403 = Forbidden 
•404 = Not Found 
•405 = Method Not Allowed 
•409 = Conflict 
•450 = Blocked by Windows Parental Controls 
•500 = Internal Server Error 
•501 = Not Implemented 
Percorso 7 
Architetture Web 
64
HTTP msg – header lines 
•Header lines provide information about the request/response or about the object sent in the message body 
•The header lines are in the following format: 
–One line per header 
–Form:”Header-Name: value” 
•HTTP/1.0 defines 16 headers (none required); HTTP/1.1 defines 46 headers and 1 is required in requests: 
–Host: 
Percorso 7 
Architetture Web 
65
Request header 
• Accept; 
•| Accept-Charset; 
•| Accept-Encoding; 
•| Accept-Language; 
•| Authorization; 
•| Expect; 
•| From; 
•| Host; 
•| If-Match; 
•| If-Modified-Since; 
•| If-None-Match; 
•| If-Range; 
•| If-Unmodified-Since; 
•| Max-Forwards; 
•| Proxy-Authorization; 
•| Range; 
•| Referer; 
•| TE; 
•| User-Agent ; 
Percorso 7 
Architetture Web 
66
Response Header 
• Accept-Ranges; 
•| Age; 
•| Etag; 
•| Location; 
•| Proxy-Authenticate; 
•| Retry-After; 
•| Server; 
•| Vary; 
•| WWW-Authenticate; 
Percorso 7 
Architetture Web 
67
General headers 
• Cache-Control 
•| Connection 
•| Date 
•| Pragma 
•| Trailer 
•| Transfer-Encoding 
•| Upgrade 
•| Via 
•| Warning 
Percorso 7 
Architetture Web 
68
Message body 
•An HTTP message may have a body of data sent after the header lines. 
•In a response the body contains the resource returned to the client 
–Images 
–text/plain, text/html 
–... 
•In a request it may contain the data entered by the user in a form or a file to upload, etc. 
Percorso 7 
Architetture Web 
69
Content Type 
•Proper name: Internet Media Type 
–Also known as MIME type 
•Parts: Type, SubType, Optional Parameters 
•x- prefix for nonstandard types or subtypes 
•vnd. prefix for vendor specific subtypes 
Percorso 7 
Architetture Web 
70
Content Type Examples 
Content-Type 
File 
text/plain 
Plain text 
text/xml 
XML 
text/html 
HTML 
image/png 
PNG image 
audio/basic 
Wave audio 
audio/mpeg 
MPEG audio (MP3) 
video/quicktime 
Quicktime Video 
application/pdf 
Adobe PDF document 
application/javascript 
JavaScript 
application/vnd.ms-powerpoint 
PowerPoint file 
application/x-rar-compressed 
RAR file 
Percorso 7 
Architetture Web 
71
Message body 
•Some HTTP headers are used to describe the body content: 
– Allow 
–| Content-Encoding 
–| Content-Language 
–| Content-Length 
–| Content-Location 
–| Content-MD5 
–| Content-Range 
–| Content-Type 
–| Expires 
–| Last-Modified 
–| extension-header n 
Percorso 7 
Architetture Web 
72
HTTP Authentication 
•Basic Authentication 
–Easy to do, but plain text. Easy to reverse engineer. Less of an issue when used with SSL. 
•Digest Authentication 
–Harder to do, still plain text. Hard (impossible?) to reverse engineer because of hashing. 
•NTLM Authentication 
–Hard to do, Windows specific. Hard (impossible?) to reverse engineer. 
Percorso 7 
Architetture Web 
73
HTTP methods: HEAD 
•The HEAD method is like the GET except it asks the server to return the response headers, only. Is useful for checking the characteristics of a resource without actually downloading it. 
•The response to a HEAD request never contains a message body, only the initial line and the headers. 
Percorso 7 
Architetture Web 
74
HTTP methods: POST 
•Used to send data to the server 
•A POST request is different from the GET request as: 
–There's a block of data sent with the request in the request message body 
–The request URI is not a resource to retrieve, it's usually a program or a server page that handles the sent data 
–The HTTP response is usually not-static (generated depending on the received data) 
Percorso 7 
Architetture Web 
75
GET vs POST 
•The most common use of the POST method is to submit data gathered from user forms 
•Also the GET can be used to submit form data however, the data is encoded in the request URI 
–http://www.example.com/example.html?var=This+is+a+simple+%26+short+test. 
Percorso 7 
Architetture Web 
76
HTTP as transport layer 
•HTTP is used as “transport” for many resources / protocols 
•Protocols: 
–SOAP (Simple Object Access Protocol) 
–XML-RPC 
–WebDAV 
•Resources: 
–Text (plain, HTML, XHTML, ...) 
–Images (gif, jpeg, ...) 
–.... 
Percorso 7 
Architetture Web 
77
•These slides are licensed under a Creative Commons 
•Attribution Non Commercial Share Alike 4.0 International 
•To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ 
•Versione in Italiano: 
•https://creativecommons.org/licenses/by-nc- sa/4.0/deed.it

More Related Content

Viewers also liked

Servizio Poli@Home - e-Learning al Politecnico di Torino
Servizio Poli@Home - e-Learning al Politecnico di TorinoServizio Poli@Home - e-Learning al Politecnico di Torino
Servizio Poli@Home - e-Learning al Politecnico di Torino
Fulvio Corno
 
Interfaccia utente basata su eye-tracking per sistemi di controllo ambientale
Interfaccia utente basata su eye-tracking per sistemi di controllo ambientaleInterfaccia utente basata su eye-tracking per sistemi di controllo ambientale
Interfaccia utente basata su eye-tracking per sistemi di controllo ambientale
Luigi De Russis
 
Copyright e Licenze (Aperte) per i contenuti didattici
 Copyright e Licenze (Aperte) per i contenuti didattici  Copyright e Licenze (Aperte) per i contenuti didattici
Copyright e Licenze (Aperte) per i contenuti didattici
Fulvio Corno
 
Condivisione di dischi - NFS - Reti miste Windows/Linux - SMB e NetBIOS - Sam...
Condivisione di dischi - NFS - Reti miste Windows/Linux - SMB e NetBIOS - Sam...Condivisione di dischi - NFS - Reti miste Windows/Linux - SMB e NetBIOS - Sam...
Condivisione di dischi - NFS - Reti miste Windows/Linux - SMB e NetBIOS - Sam...
Fulvio Corno
 
Presentazione Laurea Magistrale in Ingegneria Informatica del Politecnico di ...
Presentazione Laurea Magistrale in Ingegneria Informatica del Politecnico di ...Presentazione Laurea Magistrale in Ingegneria Informatica del Politecnico di ...
Presentazione Laurea Magistrale in Ingegneria Informatica del Politecnico di ...
Fulvio Corno
 
Prova 1 - private
Prova 1 - privateProva 1 - private
Prova 1 - private
Lara Ghiotto
 
Clean Code
Clean CodeClean Code
Clean Code
Luigi De Russis
 
Linux Kernel, driver e compilazione
Linux Kernel, driver e compilazioneLinux Kernel, driver e compilazione
Linux Kernel, driver e compilazione
Fulvio Corno
 
Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8
Fulvio Corno
 
Ambient Intelligence: Theme of the Year 2016
Ambient Intelligence: Theme of the Year 2016Ambient Intelligence: Theme of the Year 2016
Ambient Intelligence: Theme of the Year 2016
Fulvio Corno
 
Introduzione al Corso - Tecniche di Programmazione 2015
Introduzione al Corso - Tecniche di Programmazione 2015Introduzione al Corso - Tecniche di Programmazione 2015
Introduzione al Corso - Tecniche di Programmazione 2015
Fulvio Corno
 
Ingegneri e disabilità: abbattere il muro
Ingegneri e disabilità: abbattere il muroIngegneri e disabilità: abbattere il muro
Ingegneri e disabilità: abbattere il muro
Fulvio Corno
 
Ausili: definizioni e normative - Tecnologie per la Disabilità 2014/2015
Ausili: definizioni e normative - Tecnologie per la Disabilità 2014/2015Ausili: definizioni e normative - Tecnologie per la Disabilità 2014/2015
Ausili: definizioni e normative - Tecnologie per la Disabilità 2014/2015
Fulvio Corno
 
Gli anelli mancanti per l’Ambient Intelligence
Gli anelli mancanti per l’Ambient IntelligenceGli anelli mancanti per l’Ambient Intelligence
Gli anelli mancanti per l’Ambient Intelligence
Fulvio Corno
 
Ambient Intelligence - Course Introduction
Ambient Intelligence - Course IntroductionAmbient Intelligence - Course Introduction
Ambient Intelligence - Course Introduction
Fulvio Corno
 
Introduzione al Corso - Tecnologie per la Disabilità 2014/2015
Introduzione al Corso - Tecnologie per la Disabilità 2014/2015Introduzione al Corso - Tecnologie per la Disabilità 2014/2015
Introduzione al Corso - Tecnologie per la Disabilità 2014/2015
Fulvio Corno
 
PowerOnt: an ontology-based approach for power consumption estimation in Smar...
PowerOnt: an ontology-based approach for power consumption estimation in Smar...PowerOnt: an ontology-based approach for power consumption estimation in Smar...
PowerOnt: an ontology-based approach for power consumption estimation in Smar...
Luigi De Russis
 
AmI 2015 - Databases in Python
AmI 2015 - Databases in PythonAmI 2015 - Databases in Python
AmI 2015 - Databases in Python
Fulvio Corno
 
Ambient Intelligence Design Process
Ambient Intelligence Design ProcessAmbient Intelligence Design Process
Ambient Intelligence Design Process
Fulvio Corno
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFX
Fulvio Corno
 

Viewers also liked (20)

Servizio Poli@Home - e-Learning al Politecnico di Torino
Servizio Poli@Home - e-Learning al Politecnico di TorinoServizio Poli@Home - e-Learning al Politecnico di Torino
Servizio Poli@Home - e-Learning al Politecnico di Torino
 
Interfaccia utente basata su eye-tracking per sistemi di controllo ambientale
Interfaccia utente basata su eye-tracking per sistemi di controllo ambientaleInterfaccia utente basata su eye-tracking per sistemi di controllo ambientale
Interfaccia utente basata su eye-tracking per sistemi di controllo ambientale
 
Copyright e Licenze (Aperte) per i contenuti didattici
 Copyright e Licenze (Aperte) per i contenuti didattici  Copyright e Licenze (Aperte) per i contenuti didattici
Copyright e Licenze (Aperte) per i contenuti didattici
 
Condivisione di dischi - NFS - Reti miste Windows/Linux - SMB e NetBIOS - Sam...
Condivisione di dischi - NFS - Reti miste Windows/Linux - SMB e NetBIOS - Sam...Condivisione di dischi - NFS - Reti miste Windows/Linux - SMB e NetBIOS - Sam...
Condivisione di dischi - NFS - Reti miste Windows/Linux - SMB e NetBIOS - Sam...
 
Presentazione Laurea Magistrale in Ingegneria Informatica del Politecnico di ...
Presentazione Laurea Magistrale in Ingegneria Informatica del Politecnico di ...Presentazione Laurea Magistrale in Ingegneria Informatica del Politecnico di ...
Presentazione Laurea Magistrale in Ingegneria Informatica del Politecnico di ...
 
Prova 1 - private
Prova 1 - privateProva 1 - private
Prova 1 - private
 
Clean Code
Clean CodeClean Code
Clean Code
 
Linux Kernel, driver e compilazione
Linux Kernel, driver e compilazioneLinux Kernel, driver e compilazione
Linux Kernel, driver e compilazione
 
Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8
 
Ambient Intelligence: Theme of the Year 2016
Ambient Intelligence: Theme of the Year 2016Ambient Intelligence: Theme of the Year 2016
Ambient Intelligence: Theme of the Year 2016
 
Introduzione al Corso - Tecniche di Programmazione 2015
Introduzione al Corso - Tecniche di Programmazione 2015Introduzione al Corso - Tecniche di Programmazione 2015
Introduzione al Corso - Tecniche di Programmazione 2015
 
Ingegneri e disabilità: abbattere il muro
Ingegneri e disabilità: abbattere il muroIngegneri e disabilità: abbattere il muro
Ingegneri e disabilità: abbattere il muro
 
Ausili: definizioni e normative - Tecnologie per la Disabilità 2014/2015
Ausili: definizioni e normative - Tecnologie per la Disabilità 2014/2015Ausili: definizioni e normative - Tecnologie per la Disabilità 2014/2015
Ausili: definizioni e normative - Tecnologie per la Disabilità 2014/2015
 
Gli anelli mancanti per l’Ambient Intelligence
Gli anelli mancanti per l’Ambient IntelligenceGli anelli mancanti per l’Ambient Intelligence
Gli anelli mancanti per l’Ambient Intelligence
 
Ambient Intelligence - Course Introduction
Ambient Intelligence - Course IntroductionAmbient Intelligence - Course Introduction
Ambient Intelligence - Course Introduction
 
Introduzione al Corso - Tecnologie per la Disabilità 2014/2015
Introduzione al Corso - Tecnologie per la Disabilità 2014/2015Introduzione al Corso - Tecnologie per la Disabilità 2014/2015
Introduzione al Corso - Tecnologie per la Disabilità 2014/2015
 
PowerOnt: an ontology-based approach for power consumption estimation in Smar...
PowerOnt: an ontology-based approach for power consumption estimation in Smar...PowerOnt: an ontology-based approach for power consumption estimation in Smar...
PowerOnt: an ontology-based approach for power consumption estimation in Smar...
 
AmI 2015 - Databases in Python
AmI 2015 - Databases in PythonAmI 2015 - Databases in Python
AmI 2015 - Databases in Python
 
Ambient Intelligence Design Process
Ambient Intelligence Design ProcessAmbient Intelligence Design Process
Ambient Intelligence Design Process
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFX
 

Similar to Architetture web - Linguaggi e standard - Web server, application server, database server - Protocollo HTTP

Introduzione a Internet
Introduzione a InternetIntroduzione a Internet
Introduzione a Internet
dadahtml
 
REST API fantastiche e dove trovarle
REST API fantastiche e dove trovarleREST API fantastiche e dove trovarle
REST API fantastiche e dove trovarle
Marco Breveglieri
 
Sviluppo di servizi REST per Android - Luca Masini
Sviluppo di servizi REST per Android - Luca Masini Sviluppo di servizi REST per Android - Luca Masini
Sviluppo di servizi REST per Android - Luca Masini Whymca
 
Esempi pratici
Esempi praticiEsempi pratici
Esempi pratici
DotNetMarche
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
Pietro Libro
 
Applicazioni web based
Applicazioni web basedApplicazioni web based
Applicazioni web based
Marco Liverani
 
Come funziona la navigazione Web
Come funziona la navigazione WebCome funziona la navigazione Web
Come funziona la navigazione Webextrategy
 
WeWantWeb - WCF Data Services
WeWantWeb - WCF Data ServicesWeWantWeb - WCF Data Services
WeWantWeb - WCF Data Services
DomusDotNet
 
Costruisci il tuo Sito Web - 1a parte
Costruisci il tuo Sito Web - 1a parteCostruisci il tuo Sito Web - 1a parte
Costruisci il tuo Sito Web - 1a parte
Michele Squillantini
 
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Andrea Dottor
 
2 Protocolli Applicativi
2 Protocolli Applicativi2 Protocolli Applicativi
2 Protocolli Applicativiacapone
 
Dominopoint meet the experts 2015 - XPages
Dominopoint   meet the experts 2015 - XPagesDominopoint   meet the experts 2015 - XPages
Dominopoint meet the experts 2015 - XPages
Dominopoint - Italian Lotus User Group
 
Applicazioni HTML5 Superveloci - Salvatore Romeo
Applicazioni HTML5 Superveloci - Salvatore RomeoApplicazioni HTML5 Superveloci - Salvatore Romeo
Applicazioni HTML5 Superveloci - Salvatore Romeo
marcocasario
 
5. Applicazioni Web e CMS
5. Applicazioni Web e CMS5. Applicazioni Web e CMS
5. Applicazioni Web e CMS
Roberto Polillo
 
Alla scoperta di gRPC
Alla scoperta di gRPCAlla scoperta di gRPC
Alla scoperta di gRPC
Andrea Dottor
 
Laboratorio Di Basi Di Dati 07 Programmazione Web Lato Server
Laboratorio Di  Basi Di  Dati 07  Programmazione  Web Lato ServerLaboratorio Di  Basi Di  Dati 07  Programmazione  Web Lato Server
Laboratorio Di Basi Di Dati 07 Programmazione Web Lato Serverguestbe916c
 
Web Project - LESSON 1
Web Project - LESSON 1Web Project - LESSON 1
Web Project - LESSON 1Yunikon Design
 
Cert03 70-486 developing asp.net mvc 4 web applications
Cert03   70-486 developing asp.net mvc 4 web applicationsCert03   70-486 developing asp.net mvc 4 web applications
Cert03 70-486 developing asp.net mvc 4 web applicationsDotNetCampus
 

Similar to Architetture web - Linguaggi e standard - Web server, application server, database server - Protocollo HTTP (20)

Introduzione a Internet
Introduzione a InternetIntroduzione a Internet
Introduzione a Internet
 
REST API fantastiche e dove trovarle
REST API fantastiche e dove trovarleREST API fantastiche e dove trovarle
REST API fantastiche e dove trovarle
 
8 Www2009 Parte2
8 Www2009 Parte28 Www2009 Parte2
8 Www2009 Parte2
 
Sviluppo di servizi REST per Android - Luca Masini
Sviluppo di servizi REST per Android - Luca Masini Sviluppo di servizi REST per Android - Luca Masini
Sviluppo di servizi REST per Android - Luca Masini
 
Esempi pratici
Esempi praticiEsempi pratici
Esempi pratici
 
Corso Java 3 - WEB
Corso Java 3 - WEBCorso Java 3 - WEB
Corso Java 3 - WEB
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Applicazioni web based
Applicazioni web basedApplicazioni web based
Applicazioni web based
 
Come funziona la navigazione Web
Come funziona la navigazione WebCome funziona la navigazione Web
Come funziona la navigazione Web
 
WeWantWeb - WCF Data Services
WeWantWeb - WCF Data ServicesWeWantWeb - WCF Data Services
WeWantWeb - WCF Data Services
 
Costruisci il tuo Sito Web - 1a parte
Costruisci il tuo Sito Web - 1a parteCostruisci il tuo Sito Web - 1a parte
Costruisci il tuo Sito Web - 1a parte
 
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
 
2 Protocolli Applicativi
2 Protocolli Applicativi2 Protocolli Applicativi
2 Protocolli Applicativi
 
Dominopoint meet the experts 2015 - XPages
Dominopoint   meet the experts 2015 - XPagesDominopoint   meet the experts 2015 - XPages
Dominopoint meet the experts 2015 - XPages
 
Applicazioni HTML5 Superveloci - Salvatore Romeo
Applicazioni HTML5 Superveloci - Salvatore RomeoApplicazioni HTML5 Superveloci - Salvatore Romeo
Applicazioni HTML5 Superveloci - Salvatore Romeo
 
5. Applicazioni Web e CMS
5. Applicazioni Web e CMS5. Applicazioni Web e CMS
5. Applicazioni Web e CMS
 
Alla scoperta di gRPC
Alla scoperta di gRPCAlla scoperta di gRPC
Alla scoperta di gRPC
 
Laboratorio Di Basi Di Dati 07 Programmazione Web Lato Server
Laboratorio Di  Basi Di  Dati 07  Programmazione  Web Lato ServerLaboratorio Di  Basi Di  Dati 07  Programmazione  Web Lato Server
Laboratorio Di Basi Di Dati 07 Programmazione Web Lato Server
 
Web Project - LESSON 1
Web Project - LESSON 1Web Project - LESSON 1
Web Project - LESSON 1
 
Cert03 70-486 developing asp.net mvc 4 web applications
Cert03   70-486 developing asp.net mvc 4 web applicationsCert03   70-486 developing asp.net mvc 4 web applications
Cert03 70-486 developing asp.net mvc 4 web applications
 

Architetture web - Linguaggi e standard - Web server, application server, database server - Protocollo HTTP

  • 1.
  • 2. Argomenti •Architetture web •Livelli, server, standard, protocolli •HTTP (Hypertext Transfer Protocol) Percorso 7 Architetture Web 2
  • 3. Evoluzione delle architetture web Percorso 7 Architetture Web 3 http://www.evolutionoftheweb.com
  • 4. Architettura ad N livelli Browser Internet infrastructure Web Server Application Server Database Server •Ciascun livello ha un ruolo ben definito •Uno o più “server” implementano ciascun livello •I server possono condividere lo stesso hardware •La comunicazione tra i livelli avviene attraverso meccanismi di rete Percorso 7 Architetture Web 4 3rd party services Client
  • 5. Architettura generale Percorso 7 Architetture Web 5 Client Internet Server(s) • Storicamente, un browser web • Ma anche: • Applicazione Mobile • Applicazione Desktop • Altra applicazione server
  • 6. Componenti •Una o più connessioni ad Internet (attraverso un ISP) •Uno o più server che implementino ciascun livello dell’architettura •Una o più reti fisiche per interconnettere I server •Uno o più apparati di rete (router, firewall, switch) per implementare le politiche di comunicazione e di sicurezza. Percorso 7 Architetture Web 6
  • 7. Definitione •“Server” si può definire come –Definizione logica: Un processo, in esecuzione su un computer host, che fornisce informazione ad un client al ricevimento di una richiesta. –Definizione fisica: Un computer host, collegato in rete, che contiene delle informazioni (es. Siti web) e che risponde alle richieste per tali informazioni Percorso 7 Architetture Web 7
  • 8. Server Web •Gestisce il protocollo HTTP (riceve le richieste e fornisce le risposte) –Riceve richieste dai client –Legge contenuti e pagine statiche dal filesystem –Attiva l’application server per le pagine dimaniche e per la generazione di contenuti dinamici server-side –Fornisce al client un file (HTML o altro) come risposta •Una connessione HTTP per ciascuna richiesta •Multi-process, Multi-threaded, Process pool Percorso 7 Architetture Web 8
  • 9. Esempio Percorso 7 Architetture Web 9 Client Web server Internet URL http request HTML files display http response page TCP/IP path browser server file system HTML send
  • 10. Standard adottati •URL (uniform resource locator) per identificare le pagine web •HTML (hyper text markup language) per costruire le pagine web •GIF (graphics interchange format), PNG (portable network graphics), JPEG, … per le immagini •HTTP (hyper text transfer protocol) per l’interazione tra client e server •TCP/IP (transmission control protocol over internet protocol) per il trasferimento di dati Percorso 7 Architetture Web 10
  • 11. URL Percorso 7 Architetture Web 11 http://elite.polito.it/~corno/index.html DNS 130.192.5.26 TCP Contact server File system URI Rewriting HTML file contents /home/corno/public_html/index.html RFC 2396 http://www.w3.org/Addressing/
  • 12. URI Basics •http://www.sadev.co.za/users/1/contact •http://www.sadev.co.za?user=1&action=contact •http://rob:pass@bbd.co.za:8044 •https://bbd.co.za/index.html#about Percorso 7 Architetture Web 12 Scheme Scheme Scheme Scheme Hostname Hostname Hostname Hostname Query Query Query Port Fragment Userinfo
  • 13. Protocollo HTTP Percorso 7 Architetture Web 13 GET /~corno/index.html HTTP/1.0 Accept: text/html Accept: image/gif User-Agent: Firefox/Windows Browser 18.3 HTTP/1.0 200 OK Date: Monday, 01-Jan-2001 00:00:00 GMT Server: Apache 1.3.0 MIME-Version: 1.0 Last-Modified: 31-Dec-2000 Content-type: text/html Content-length: 3021 <HTML> . . . RFC 2616, RFC 2617 http://www.w3.org/Protocols
  • 14. Misure di prestazione •Latenza: tempo necessario a fornire una risposta http contenente una pagina di 0 byte. Rappresenta il costo di elaborazione fisso di ciascuna pagina. –Misurata in: http/s o s/http •Throughput: massima velocità a cui una pagna di lunghezza infinita può essere inviata. –Misurata in: byte/s, MB/s Percorso 7 Architetture Web 14
  • 15. Tempo di risposta •T = Latency + ResponseBytes / Throughput •Equazione valida se: –Gli altri elementi architetturali (I/O, reti, ...) non sono sovraccarichi –Il server web non ha ancora raggiunto il massimo carico sopprtabile •Esempio: –Latency: 0,1s –ResponseBytes : 100kBytes –Throughput: 800kBytes/s –T= 0,1s+ 100KBytes / 800KBytes/s =0,225s Percorso 7 Architetture Web 15
  • 16. Transazione web statica Percorso 7 Architetture Web 16 Browser Web server Disk access t0 t1 t2 t3 t4 t6 t7 t8 t9 t5 t’0 t’1 total response time server response time user think time network transfer time
  • 17. General Architecture Percorso 7 Architetture Web 17 internet Web application (PHP, JSP, …) Browser Display Mouse/ Keyboard Web server (Apache, IIS) HTML file Image file Layout engine IMG IMG HTM HTM
  • 18. The most adopted web servers Percorso 7 Architetture Web 18 Source: http://news.netcraft.com/ http://news.netcraft.com/archives/2014/03/03/march-2014-web-server-survey.html
  • 19. Application server •Generazione delle pagine e dei contenuti dinamici •Gestisce la logica operativa e funzionale (business logic) del sito •Livello intermedio tra il front-end (web) ed il back- end (database) •Implementa i meccanismi di sessione (gestione cookie) •Realizzabile con diverse tecnologie, architetture e linguaggi di programmazione Percorso 7 Architetture Web 19
  • 20. Transazione web dinamica Percorso 7 Architetture Web 20 Client Web server Internet URL & data http request with data display http response page TCP/IP com-mand browser server application HTML send Application para-meters logic
  • 21. Standard adottati •Estensioni HTTP per inviare dati –HTTP-POST –URL-encoding in HTTP-GET requests •Tecnologie per integrare codice applicativo nel server web –java servlets –ASP (active server pages), JSP, PHP, PERL, Python as new languages for application development •Cookie per gestire lo stato di una sessione Percorso 7 Architetture Web 21
  • 22. URL (HTTP GET) Percorso 7 Architetture Web 22 http://www.cad.polito.it/pap/pap.pl?author=Corno CPU Application HTML Parameters Disk Libraries
  • 23. Transazione web dinamica Percorso 7 Architetture Web 23 Browser Web server Application server t0 t1 t2 t3 t5 t6 t7 t8 t9 t4 total response time application time total server time t’0 t’1
  • 24. Server database •Memorizza i dati su cui lavora l’application server •Esegue le interrogazioni (query) richieste dall’application server: –Aggiorna i dati memorizzati –Inserisce nuovi dati –Restituisce i risultati delle ricerche •Le query più complesse o più frequenti possono essere implementate all’interno del database, per mezzo di «stored procedure» e/o query parametriche. Percorso 7 Architetture Web 24
  • 25. Esempio Percorso 7 Architetture Web 25 Client Web server Internet URL & data http req http resp display page TCP/IP com-mand browser server application HTML send Application para-meters database data Database query
  • 26. Standard adottati •Basi di dati relazionali (RDMBS) •SQL (structured query language) •JDBC/ODBC per accedere alle basi dati Percorso 7 Architetture Web 26
  • 27. Database server •Queries are almost always in SQL –SELECT * FROM table; –.... •Often adopts the relational database model –Other models can be used •Object model •Triple model •The most advanced/complete solutions are called Transaction servers Percorso 7 Architetture Web 27
  • 28. Database-driven transaction Percorso 7 Architetture Web 28 Browser Web server Application server Database server t0 t1 t2 t3 t5 t6 t7 t8 t9 t4 t’0 t’1 total response time application time total server time database time
  • 29. Esempio (PHP) •<?php •$query = “SELECT doc_id FROM key_doc_index, keywords WHERE key_doc_index.key_id = keywords.id AND keywords.key = $_REQUEST[“query”];”; •$rowset = mysql_query($query); •while($row = mysql_fetch_row($rowset)) •{ •//elaborate data •} •?> Percorso 7 Architetture Web 29 The application composes the query The query is sent to the db-server and a rowset containing the results is returned The application elaborates the data
  • 30. General Architecture Percorso 7 Architetture Web 30 internet Web application (ASP, PHP, JSP, …) Browser Display Mouse/ Keyboard Web server (Apache, IIS) HTML file Image file Layout engine IMG IMG HTM HTM Database Database Server DBMS SQL
  • 31. Interazione lato client •Gli standard W3C regolano l’interazione client- server, ma gli utenti vogliono maggiore interazione sul client •Nuovi standard e linguaggi permettono dei comportamenti dinamici all’interno di una pagina caricata, senza coinvolgere il server Percorso 7 Architetture Web 31
  • 32. General Architecture Percorso 7 Architetture Web 32 internet Web application (ASP, PHP, JSP, …) Browser Display Mouse/ Keyboard Web server (Apache, IIS) HTML file Image file Layout engine IMG IMG HTM HTM Database Database Server DBMS SQL Javascript engine JS CSS HTM DOM CSS stylesheets Javascript JS CSS
  • 33. Web 2.0 •Web applications support social interaction models •Peer exchange and user-contributed content instead of rigid publisher/reader pattern –Online communities •Rich, dynamic, interactive user interfaces •Integration of contents across web sites (mashups) Percorso 7 Architetture Web 33
  • 34. Rich-Client Asynchronous Transactions Percorso 7 Architetture Web 34 Client Web server Internet URL http display http page TCP/IP com-mand browser server application HTML send Application para-meters database data Database query Client-side Application runtime events DOM http XML/JSON
  • 35. Adopted standards •Dynamic HTML: DOM, Javascript, CSS –JavaScript, Flash to handle a runtime environment on the browser –DOM (XHTML Document Object Model) to allow on-the fly modification of the web page –CSS 2.1 to modify attribute and handle objects •AJAX: Asynchronous Javascript and XML –XMLHttpRequest for asynchronous communication to the server –Data transfer formats: JSON, XML, RDF, RSS, Atom, FOAF, ... •Mash-up technology Percorso 7 Architetture Web 35
  • 36. Rich-client transaction Percorso 7 Architetture Web 36 Browser Web server Application server Database server t9 t0 t1 t2 t3 t5 t6 t7 t8 t4 t’0 t’1 Runtime
  • 37. General Architecture Percorso 7 Architetture Web 37 internet Web application (ASP, PHP, JSP, …) Browser Display Mouse/ Keyboard Web server (Apache, IIS) HTML file Image file Layout engine IMG IMG HTM HTM Database Database Server DBMS SQL Javascript engine JS CSS HTM DOM CSS stylesheets Javascript JS CSS Data XML, JSON
  • 38. Architettura generale del web Percorso 7 Architetture Web 38 internet Database Applicazione web (ASP, PHP, JSP, …) Browser Schermo Mouse/ Tastiera Server web (Apache, IIS) Server database DBMS File HTML File Immagini Fogli di stile CSS Javascript Motore Layout Motore Javascript IMG JS JS IMG CSS CSS HTM HTM HTM SQL DOM Dati XML, JSON XML, JSON Questo è sufficiente per il sito di ricette di cucina della nonna… … ma nella realtà il mondo enterprise è molto più complesso
  • 39. Distributed transactions Percorso 7 Architetture Web 39 Client Web server Internet Application Web server Internet Application XML/JSON
  • 40. Requisiti del mondo “reale”… •The users •Functionality •Flexibility •Portability •Reliability •Security •Integrity •Maintenance •Performance •Scalability •Costs •Maintenance •Development times •Interactions with existing systems •Interactions with the “physical” world Percorso 7 Architetture Web 40
  • 41. Il problema delle sessioni •Il protocollo HTTP è “senza memoria” (stateless) •Ogni richiesta è indipendente dalle altre, e non può “ricordare” il percorso precedente di un utente •Le variabili di input di ogni pagina possono dipendere solamente dai FORM nella pagina precedente •Gli utenti, invece, vorrebbero avere l’impressione di una navigazione continua, in cui una scelta compiuta in una pagina venga “ricordata” in tutte le pagine successive. •È necessario costruire una astrazione di una sessione di navigazione •Sessione = sequenza di pagine, visitata sullo stesso sito dallo stesso utente con lo stesso browser nella stessa seduta di navigazione, che presentino una consequenzialità logica Percorso 7 Architetture Web 41
  • 42. login: password: fulvio **** Login accettato. Benvenuto, fulvio Controlla la posta! home.html login.php VAI Utente attivo: fulvio La tua posta: XXX posta.php login.php?user=fulvio&pass=xyzq ??? Esempio •L’utente inserisce i propri username e password sulla prima pagina che visita •La pagina successiva sarà necessariamente una pagina dinamica che “valida” il login •Tutte le pagine successive dovranno conoscere il nome dell’utente Percorso 7 Architetture Web 42
  • 43. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Pagina di login</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1>Inserisci i tuoi dati</h1> <form method="GET" action="login.php"> Nome utente: <input type="text" name="user" /> <br /> Password: <input type="password" name="pass" /> <br /> <input type="submit" /> </form> </body> </html> Percorso 7 Architetture Web 43
  • 44. Le soluzioni possibili •URL rewriting •Variabili nascoste nei FORM •Cookie •Session management Percorso 7 Architetture Web 44
  • 45. Cookie •Un cookie è una (piccola) quantità di informazione che il server può memorizzare sul browser •Nella risposta http il server aggiunge un comando di intestazione “set cookie” •Il browser si impegna a restituire al server il cookie ad ogni nuova richiesta http che farà •Il cookie è composto da –Nome –Valore –Scadenza –Dominio •Esempio: Nome: “user”, valore: “fulvio”, scadenza: “1200”, dominio: “miosito.it” Percorso 7 Architetture Web 45
  • 46. Cookie •Quando login.php valida la password, può settare un cookie sul browser •La pagina posta.php può leggere il cookie, che il server riceverà nuovamente dal browser •Accesso ai cookie da PHP: –Per scrivere: setcookie("nome", "valore") •bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]] ) •Deve essere chiamata prima di ogni contenuto HTML (anche spazi!) –Per leggere: $_COOKIE["nome"] –Per verificare: if( isset($_COOKIE["nome"]) ) ... –Per cancellare: setcookie("nome", "") Percorso 7 Architetture Web 46
  • 47. Pratica consigliata •Tra le alternative viste, la più conveniente è l’utilizzo dei cookie, poiché: –È sufficiente fare una sola setcookie all’inizio –È possibile settare più cookie relative a diverse variabili –Non occorre modificare né i link esistenti né i form esistenti •Svantaggi: –Non è possibile memorizzare informazioni voluminose –Non è “educato” memorizzare molti cookie diversi –Non è consigliabile fidarsi dei dati memorizzati sul browser dell’utente –È possibile che il browser rifiuti di restituire i cookie memorizzati Percorso 7 Architetture Web 47
  • 48. Session management •È possibile memorizzare più variabili con un solo cookie (breve): •Il cookie memorizza un “numero magico”, diverso per ogni nuova sessione •nome="session" value="123456" •Il server memorizza, da qualche parte, le variabili di sessione associate al numero magico •Session=123456  "user" = "fulvio" •Può essere memorizzato nella memoria del web server, oppure in un file privato del server (es. session.123456.variables), oppure in una tabella di database (Session, Name, Value) •Ad ogni nuova pagina, il cookie ricevuto può “sbloccare” le variabili opportune e renderle disponibili nella pagina. Percorso 7 Architetture Web 48
  • 49. Session management in PHP •Attivare la sessione: –session_start() •Nessun parametro, va chiamata prima di ogni altra cosa •Crea una nuova sessione o recupera quella esistente •Crea un cookie di nome simile a PHPSESSID123456 –Il vettore $_SESSION["nome"] può essere usato per memorizzare le variabili associate con la sessione: •$_SESSION["user"] = "fulvio" •echo $_SESSION["user"] •If ( isset( $_SESSION["user"] ) ) ... •Chiudere la sessione: –Scade automaticamente dopo 20-30 minuti –Scade automaticamente chiudendo il browser –Può essere “resettata” con session_destroy() Percorso 7 Architetture Web 49
  • 50. <?php session_start() ; $user = $_REQUEST["user"] ; $pass = $_REQUEST["pass"] ; if($user == "fulvio" && $pass == "xyz") { // login OK $_SESSION["user"] = $user ; $login = 1 ; } else { // login errato $login = 0 ; } ?> <html> <head> <title>Controllo login</title> </head> <body> <?php if($login == 1) { echo "<p>Benvenuto, $user</p>n"; echo "<p>Controlla la tua <a href="posta.php">posta</a></p>n" ; } else { echo "<p>ERRORE: login non valido, <a href="home.html">riprova</a></p>n" ; } //echo "<p>Password: $pass</p>n" ; ?> </body> </html> Percorso 7 Architetture Web 50
  • 51. Esempio: posta.php <?php session_start() ; ?> <html> <head> <title>La tua posta</title> </head> <body> <? if(isset($_SESSION["user"])) { $user = $_SESSION["user"] ; echo "<p>Ecco la tua posta, $user</p>n" ; /* stampa la posta... */ } else { echo "<p>ERRORE: devi prima fare il <a href="home.html">login</a></p>n" ; } ?> </body> Percorso 7 Architetture Web 51
  • 53. What is HTTP? •HTTP stands for Hypertext Transfer Protocol •It is the network protocol used to delivery virtually all data over the WWW: –Images –HTML files –Query results –Etc. •HTTP takes places over TCP/IP connections Percorso 7 Architetture Web 53 http://www.ietf.org/rfc/rfc2616.txt
  • 54. HTTP clients and servers •A browser is an HTTP client because it sends requests to an HTTP server, which then sends responses back to the client. •The standard port for HTTP servers to listen on is 80, though they can use any port. Percorso 7 Architetture Web 54 Http - request Http - response
  • 55. HTTP messages •The format of the request and response messages are similar (English-oriented). They consist of: –An initial line –Zero or more header lines –A blank line (CRLF) –An optional message body Percorso 7 Architetture Web 55 Initial line header1: value1 header2: value2 header3: value3 message body...
  • 56. Header Example •HEAD /index.html HTTP/1.1 •Host: www.example.com Percorso 7 Architetture Web 56 HTTP/1.1 200 OK Date: Mon, 23 May 2005 22:38:34 GMT Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux) Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT Etag: "3f80f-1b6-3e1cb03b" Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8 Request Response
  • 57. HTTP Basics •HTTP is not HTML •HTTP is stateless Percorso 7 Architetture Web 57 HTTP (Request, Response) Header Body URI Method Status Code http://www.sadev.co.za GET 200 text Content Type text/plain
  • 58. HTTP msg – initial line •The initial line is different for the request and the response. •A request initial line has three parts separated by white spaces: –A method name –The local path of the requested resource –The version of the HTTP being used •GET /path/to/file/index.html HTTP/1.0 Percorso 7 Architetture Web 58
  • 59. HTTP msg – initial line –The method name is always in upper case. –There are several methods for a HTTP request •GET (most commonly used) •POST (used for sending form data) •HEAD •... –The path is the part of the URL after the host name •http://www.tryme.com/examples/example1.html Percorso 7 Architetture Web 59
  • 60. HTTP Method Basics HEAD Gets just the HTTP header GET Gets HTTP head & body POST Submits data in the body to the server PUT Uploads a resource DELETE Deletes a resource TRACE Echo’s back the request OPTIONS Gets a list of supported methods CONNECT Converts to a TCP/IP tunnel for HTTPS PATCH Apply partial modifications to a resource Percorso 7 Architetture Web 60
  • 61. HTTP msg – initial line –The HTTP version is always in the form •HTTP/x.x (uppercase) –The versions currently in use are: •HTTP/1.0 •HTTP/1.1 Percorso 7 Architetture Web 61
  • 62. HTTP msg – initial line •The response initial line is usually called status line and has also 3 parts separated by spaces: –The HTTP version –The response status code –An English phrase describing the status code •Example: –HTTP/1.0 200 OK –HTTP/1.0 404 Not Found Percorso 7 Architetture Web 62
  • 63. Response Status Codes •1xx – Informational •2xx – Success •3xx – Redirection •4xx – Client Error •5xx – Server Error Percorso 7 Architetture Web 63
  • 64. Response Status Codes •1xx – Informational •2xx – Success •3xx – Redirection •4xx – Client Error •5xx – Server Error •100 = Continue •102 = Processing •200 = OK •201 = Created •204 = No Content •206 = Partial Content •301 = Moved Permanently •302 = Found (Moved Temp) •307 = Temp Redirect •400 = Bad Request •401 = Unauthorised •402 = Payment Required •403 = Forbidden •404 = Not Found •405 = Method Not Allowed •409 = Conflict •450 = Blocked by Windows Parental Controls •500 = Internal Server Error •501 = Not Implemented Percorso 7 Architetture Web 64
  • 65. HTTP msg – header lines •Header lines provide information about the request/response or about the object sent in the message body •The header lines are in the following format: –One line per header –Form:”Header-Name: value” •HTTP/1.0 defines 16 headers (none required); HTTP/1.1 defines 46 headers and 1 is required in requests: –Host: Percorso 7 Architetture Web 65
  • 66. Request header • Accept; •| Accept-Charset; •| Accept-Encoding; •| Accept-Language; •| Authorization; •| Expect; •| From; •| Host; •| If-Match; •| If-Modified-Since; •| If-None-Match; •| If-Range; •| If-Unmodified-Since; •| Max-Forwards; •| Proxy-Authorization; •| Range; •| Referer; •| TE; •| User-Agent ; Percorso 7 Architetture Web 66
  • 67. Response Header • Accept-Ranges; •| Age; •| Etag; •| Location; •| Proxy-Authenticate; •| Retry-After; •| Server; •| Vary; •| WWW-Authenticate; Percorso 7 Architetture Web 67
  • 68. General headers • Cache-Control •| Connection •| Date •| Pragma •| Trailer •| Transfer-Encoding •| Upgrade •| Via •| Warning Percorso 7 Architetture Web 68
  • 69. Message body •An HTTP message may have a body of data sent after the header lines. •In a response the body contains the resource returned to the client –Images –text/plain, text/html –... •In a request it may contain the data entered by the user in a form or a file to upload, etc. Percorso 7 Architetture Web 69
  • 70. Content Type •Proper name: Internet Media Type –Also known as MIME type •Parts: Type, SubType, Optional Parameters •x- prefix for nonstandard types or subtypes •vnd. prefix for vendor specific subtypes Percorso 7 Architetture Web 70
  • 71. Content Type Examples Content-Type File text/plain Plain text text/xml XML text/html HTML image/png PNG image audio/basic Wave audio audio/mpeg MPEG audio (MP3) video/quicktime Quicktime Video application/pdf Adobe PDF document application/javascript JavaScript application/vnd.ms-powerpoint PowerPoint file application/x-rar-compressed RAR file Percorso 7 Architetture Web 71
  • 72. Message body •Some HTTP headers are used to describe the body content: – Allow –| Content-Encoding –| Content-Language –| Content-Length –| Content-Location –| Content-MD5 –| Content-Range –| Content-Type –| Expires –| Last-Modified –| extension-header n Percorso 7 Architetture Web 72
  • 73. HTTP Authentication •Basic Authentication –Easy to do, but plain text. Easy to reverse engineer. Less of an issue when used with SSL. •Digest Authentication –Harder to do, still plain text. Hard (impossible?) to reverse engineer because of hashing. •NTLM Authentication –Hard to do, Windows specific. Hard (impossible?) to reverse engineer. Percorso 7 Architetture Web 73
  • 74. HTTP methods: HEAD •The HEAD method is like the GET except it asks the server to return the response headers, only. Is useful for checking the characteristics of a resource without actually downloading it. •The response to a HEAD request never contains a message body, only the initial line and the headers. Percorso 7 Architetture Web 74
  • 75. HTTP methods: POST •Used to send data to the server •A POST request is different from the GET request as: –There's a block of data sent with the request in the request message body –The request URI is not a resource to retrieve, it's usually a program or a server page that handles the sent data –The HTTP response is usually not-static (generated depending on the received data) Percorso 7 Architetture Web 75
  • 76. GET vs POST •The most common use of the POST method is to submit data gathered from user forms •Also the GET can be used to submit form data however, the data is encoded in the request URI –http://www.example.com/example.html?var=This+is+a+simple+%26+short+test. Percorso 7 Architetture Web 76
  • 77. HTTP as transport layer •HTTP is used as “transport” for many resources / protocols •Protocols: –SOAP (Simple Object Access Protocol) –XML-RPC –WebDAV •Resources: –Text (plain, HTML, XHTML, ...) –Images (gif, jpeg, ...) –.... Percorso 7 Architetture Web 77
  • 78. •These slides are licensed under a Creative Commons •Attribution Non Commercial Share Alike 4.0 International •To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ •Versione in Italiano: •https://creativecommons.org/licenses/by-nc- sa/4.0/deed.it