Kiến trúc web
Các mô hình kiến trúc web
Giao thức HTTP
Mô hình MVC
Kiến trúc Web Platform
Platform
Hardware
Software modules & configurations
Choice of software platform (J2EE, .NET)
Kiến trúc Web Application
Mô hình hóa các tiến trình xử lý
Trong một lĩnh vực cụ thể
Module hóa và phức tạp
Web platform dựa trên các thành phần sau
TCP/IP
HTTP
HTML
Mô hình kiến trúc Client/Server
Là mô hình phức tạp…
Các thành của network (firewall, proxy, load
balancer)
Các thành phần của intranet (web server,
application server, database, web services)
Các thành phần ngữ nghĩa
của Web
URLs/URIs
HTTP
HTML
Dịch vụ Web: Nội dung
động và có tính tương tác
PHP, Python, Java
Clients
(browsers)
HTTP
Server
HTTP for
transport
URL/URI for
addressing
HTML/XHTML
for display
C#, PHP, Python…
for interaction
HTTP
TCP
IP
Ethernet
interface
Ethernet
Client
Router
IP
Ethernet
interface
SONET
interface
IP
SONET
interface
Ethernet
interface
SONET link
HTTP
TCP
IP
Ethernet
interface
Web server
Ethernet
Router
IP packet IP packetIP packet
TCP segment
HTTP message
Những bước xử lý của browser
Client Origin
server
HTML
http://origin/..
DNS
server
DNS query
Establish TCP connection
HTTP request
Optional parallel connections
HTTP response
HTTP
transaction
Một giao dịch của giao thức HTTP là một request
một response (một phản hồi của một request nào đó)
giữa web client và web server
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap,
image/ jpeg, image/pjpeg, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible;
MSIE 5.01; Windows NT)
Host: www.eurecom.fr
Connection: Keep-Alive
Client Origin
server
HTTP/1.1 200 OK
Date: Mon, 15 Jul 2002 08:49:00 GMT
Server: Apache/1.3.26 (Unix) PHP/4.2.1
Last-Modified: Wed, 12 Jun 2002
08:49:49 GMT
ETag: "2a-50ea-3d070b2d"
Accept-Ranges: bytes
Content-Length: 20714
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html
<html>
...
HTML
HTTP message ở dạng ASCII text, gồm:
Một dòng đầu (method, URI, HTTP version)
Method Request-URI HTTP-Version (Request-Line)
HTTP-Version Status-Code Reason-Phrase (Status-Line)
Các trường Header
field-name ":" [ field-value ]
Một dòng trống <CR>
Phần thân thông báo (tùy chọn)
Ví dụ
GET /foo.html HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/ jpeg, image/pjpeg, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)
Host: www.eurecom.fr
Connection: Keep-Alive
<CR>
GET /foo.html HTTP/1.1 request "/foo.html" using HTTP version 1.1
Accept: types of documents accepted by browser
Accept-Language: preferred language is english
Accept-Encoding: browser understands compressed documents
User-Agent: identification of browser (real type is IE 5.01)
Host: what the client thinks the server host is
Connection: keep TCP connection open until explicitly disconnected
Ví dụ:
HTTP/1.1 200 OK
Date: Mon, 15 Jul 2002 08:49:00 GMT
Server: Apache/1.3.26 (Unix) PHP/4.2.1
Last-Modified: Wed, 12 Jun 2002 08:49:49 GMT
ETag: "2a-50ea-3d070b2d"
Accept-Ranges: bytes
Content-Length: 20714
Connection: close
Content-Type: text/html
<CR>
<html>...
HTTP/1.1 200 OK document found (code 200); server is using HTTP 1.1
Date: current date at the server
Server: software run by the server
Last-Modified: most recent modification of the document
ETag: entity tag (unique identifier for the server resource, usable for caching)
Accept-Ranges: server can return subsections of a document
Content-Length: length of the body (which follows the header) in bytes
Connection: the connection will close after the server's response
Content-Type: what kind of document is included in the response
<html>... document text (follows blank line)
GET
Retrieve a resource from the
server (static file, or
dynamically-generated data)
HEAD
Get information about a
resource (but not the actual
resource)
POST
Client provides some
information to the server, e.g.,
through forms (may update
the state of the server)
PUT
Provide a new or replacement
resource to put on the server
DELETE
Remove a resource from the
server
OPTIONS (HTTP 1.1)
Request other options for an
URI (methods understood by a
server or allowed for a given
URI)
TRACE (HTTP 1.1)
Ask proxies to declare
themselves in the headers
(used for debugging)
CONNECT (HTTP 1.1)
Used for HTTPS (secure
HTTP) through a proxy
2xx: thành công
200 OK
3xx: chuyển tiếp
301 Moved Permanently
302 Found
307 Temporary Redirect
4xx: lỗi từ phía client
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
5xx: lỗi từ phía server
500 Internal Server Error
Dữ liệu cache gần người dùng hơn
Improves Web performance, reduces load on server
Cache control directives in HTTP header (no cache, age, etc.)
GET http://origin/..
Client 1
Cache
server
Origin
server
Client 2
GET http://origin/..
200 OK
200 OK
GET http://origin/..
200 OK
Cơ chế bảo mật đơn giản thông qua username/password
Basic scheme: username:password base-64 encoded
echo -n "user:password" | openssl base64
echo "c2NvdHQ6dGlnZXI=" | openssl base64 -d
GET /private/ HTTP/1.1
Client Origin
server
HTML
HTTP/1.1 200 OK
...
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="secret"
GET /private/ HTTP/1.1
Authorized: Basic SHY3GH7D3SH==
Username: joe
Password: ********
Cho phép Web servers lưu
trạng thái của Client
Dùng cặp khóa – giá trị
Thường dùng quản lý các
phiên giao dịch session
Cookie có thể truy xuất bởi
một site/domain
Server có thể định thời gian
hết hạn
Client có thể từ chối cookie,
giới hạn kích thước, thời
gian…
Client
Origin
server
GET http://origin/..
200 OK
Set-Cookie: ABC=XYZ
GET http://origin/..
Cookie: ABC=XYZ
200 OK

Preview text:

Kiến trúc web
❑ Các mô hình kiến trúc web ❑ Giao thức HTTP ❑ Mô hình MVC ❑ Kiến trúc Web Platform ▪ Platform • Hardware
• Software modules & configurations
• Choice of software platform (J2EE, .NET)
❑ Kiến trúc Web Application
▪ Mô hình hóa các tiến trình xử lý
▪ Trong một lĩnh vực cụ thể
▪ Module hóa và phức tạp
❑ Web platform dựa trên các thành phần sau ▪ TCP/IP ▪ HTTP ▪ HTML
❑ Mô hình kiến trúc Client/Server
❑ Là mô hình phức tạp…
▪ Các thành của network (firewall, proxy, load balancer)
▪ Các thành phần của intranet (web server,
application server, database, web services)
❑ Các thành phần ngữ nghĩa
❑ Dịch vụ Web: Nội dung của Web
động và có tính tương tác ▪ URLs/URIs ▪ PHP, Python, Java ▪ HTTP ▪ HTML HTML/XHTML HTTP for for display transport HTTP Server URL/URI for C#, PHP, Python… Clients addressing for interaction (browsers) Client Web server HTTP message HTTP HTTP TCP segment TCP TCP Router Router IP packet IP packet IP packet IP IP IP IP Ethernet Ethernet SONET SONET Ethernet Ethernet interface interface interface interface interface interface Ethernet SONET link Ethernet
❑ Những bước xử lý của browser http://origin/.. DNS query DNS server Client Origin
Establish TCP connection server HTTP request HTTP HTTP response transaction
Optional parallel connections HTML
◼ Một giao dịch của giao thức HTTP là một request và
một response (một phản hồi của một request nào đó)
giữa web client và web server GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/ jpeg, image/pjpeg, */* Accept-Language: en-us Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; Client MSIE 5.01; Windows NT) Origin Host: www.eurecom.fr Connection: Keep-Alive server HTTP/1.1 200 OK
Date: Mon, 15 Jul 2002 08:49:00 GMT
Server: Apache/1.3.26 (Unix) PHP/4.2.1
Last-Modified: Wed, 12 Jun 2002 08:49:49 GMT ETag: "2a-50ea-3d070b2d" Accept-Ranges: bytes Content-Length: 20714
Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html ... HTML
❑ HTTP message ở dạng ASCII text, gồm:
▪ Một dòng đầu (method, URI, HTTP version)
Method Request-URI HTTP-Version (Request-Line)
HTTP-Version Status-Code Reason-Phrase (Status-Line) ▪ Các trường Header field-name ":" [ field-value ] ▪ Một dòng trống
▪ Phần thân thông báo (tùy chọn) ❑ Ví dụ GET /foo.html HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/ jpeg, image/pjpeg, */* Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT) Host: www.eurecom.fr Connection: Keep-Alive
GET /foo.html HTTP/1.1 — request "/foo.html" using HTTP version 1.1
Accept: — types of documents accepted by browser
Accept-Language: — preferred language is english
Accept-Encoding: — browser understands compressed documents
User-Agent: — identification of browser (real type is IE 5.01)
Host: — what the client thinks the server host is
Connection: — keep TCP connection open until explicitly disconnected ❑ Ví dụ: HTTP/1.1 200 OK
Date: Mon, 15 Jul 2002 08:49:00 GMT
Server: Apache/1.3.26 (Unix) PHP/4.2.1
Last-Modified: Wed, 12 Jun 2002 08:49:49 GMT
ETag: "2a-50ea-3d070b2d" Accept-Ranges: bytes Content-Length: 20714 Connection: close Content-Type: text/html ...
HTTP/1.1 200 OK — document found (code 200); server is using HTTP 1.1
Date: — current date at the server
Server: — software run by the server
Last-Modified: — most recent modification of the document
ETag: — entity tag (unique identifier for the server resource, usable for caching)
Accept-Ranges: — server can return subsections of a document
Content-Length: — length of the body (which follows the header) in bytes
Connection: — the connection will close after the server's response
Content-Type: — what kind of document is included in the response
... — document text (follows blank line) ❑ GETDELETE Retrieve a resource from the Remove a resource from the server (static file, or server dynamically-generated data) ❑ OPTIONS (HTTP 1.1) ❑ HEAD Request other options for an Get information about a URI (methods understood by a resource (but not the actual server or allowed for a given resource) URI) ❑ POSTTRACE (HTTP 1.1) Client provides some Ask proxies to declare
information to the server, e.g., themselves in the headers through forms (may update (used for debugging) the state of the server) ❑ CONNECT (HTTP 1.1) ❑ PUT Used for HTTPS (secure Provide a new or replacement HTTP) through a proxy resource to put on the server ❑ 2xx: thành công ▪ 200 OK ❑ 3xx: chuyển tiếp ▪ 301 Moved Permanently ▪ 302 Found ▪ 307 Temporary Redirect
❑ 4xx: lỗi từ phía client ▪ 400 Bad Request ▪ 401 Unauthorized ▪ 403 Forbidden ▪ 404 Not Found
❑ 5xx: lỗi từ phía server ▪ 500 Internal Server Error
❑ Dữ liệu cache gần người dùng hơn
▪ Improves Web performance, reduces load on server
▪ Cache control directives in HTTP header (no cache, age, etc.) Cache Origin GET http://origin/.. server server Client 1 GET http://origin/.. 200 OK 200 OK Client 2 GET http://origin/.. 200 OK
❑ Cơ chế bảo mật đơn giản thông qua username/password
▪ Basic scheme: username:password base-64 encoded
echo -n "user:password" | openssl base64
echo "c2NvdHQ6dGlnZXI=" | openssl base64 -d
GET /private/ HTTP/1.1 Client Origin HTTP/1.1 401 Unauthorized server
WWW-Authenticate: Basic realm="secret" Username: joe Password: ******** GET /private/ HTTP/1.1
Authorized: Basic SHY3GH7D3SH== HTTP/1.1 200 OK ... HTML
❑ Cho phép Web servers lưu trạng thái của Client
▪ Dùng cặp khóa – giá trị
▪ Thường dùng quản lý các Client Origin phiên giao dịch session server GET http://origin/..
▪ Cookie có thể truy xuất bởi 200 OK một site/domain Set-Cookie: ABC=XYZ
▪ Server có thể định thời gian hết hạn GET http://origin/..
▪ Client có thể từ chối cookie, Cookie: ABC=XYZ
giới hạn kích thước, thời 200 OK gian…