kmutnb - internet programming 2/7
DESCRIPTION
Lecture for King Mongkut's University of Technology North Bangkok (KMUTNB) / Computer Science / Internet Programming Course by PHUPHATRANSCRIPT
Web application Architecture and HTTP Protocol
By: Mr. PHUPHA PUNYAPOTASAKUL
(ภู�ผา ปั�ญญาโพธาสกุ�ล)
04/12/23 Free template from www.brainybetty.com 2
World Wide Web
HTMLHTML
HTTPHTTP
TCP/IPTCP/IP
Network LayerNetwork Layer
04/12/23 Free template from www.brainybetty.com 3
HTTP Protocol
Hypertext Transfer Protocol (HTTP) is a communications protocol used to transfer or convey information on intranets and the World Wide Web. Its original purpose was to provide a way to publish and retrieve hypertext pages. Development of HTTP was coordinated by the W3C (World Wide Web Consortium) and the IETF (Internet Engineering Task Force), culminating in the publication of a series of RFCs, most notably RFC 2616 (June 1999), which defines HTTP/1.1, the version of HTTP in common use.
04/12/23 Free template from www.brainybetty.com 4
HTTP Specification
• HTTP 1.1http://tools.ietf.org/html/rfc2616
• HTTP 1.0http://tools.ietf.org/html/rfc1945
04/12/23 Free template from www.brainybetty.com 5
HTTP Request/Response
ServerServer
BrowserBrowser HTTP Response
HTTP Request
04/12/23 Free template from www.brainybetty.com 6
HTTP Request Methods
• HEAD– Asks for the response identical to the one that would corr
espond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
• GET– Requests a representation of the specified resource. By fa
r the most common method used on the Web today. Should not be used for operations that cause side-effects (using it for actions in web applications is a common misuse). See 'safe methods' below.
• POST– Submits data to be processed (e.g. from an HTML form
) to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both.
04/12/23 Free template from www.brainybetty.com 7
HTTP Request Methods• PUT
– Uploads a representation of the specified resource.• DELETE
– Deletes the specified resource.• TRACE
– Echoes back the received request, so that a client can see what intermediate servers are adding or changing in the request.
• OPTIONS– Returns the HTTP methods that the server supports. This can b
e used to check the functionality of a web server.• CONNECT
– Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.[1]
04/12/23 Free template from www.brainybetty.com 8
HTTP ExampleHTTP Request GET /index.html HTTP/1.1 Host: www.example.com
HTTP Response HTTP/1.1 200 OK Date: Mon, 23 May 2005 22:38:34 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8
<HTML> <HEAD> <TITLE>Title</TITLE>….
04/12/23 Free template from www.brainybetty.com 9
HTML
04/12/23 Free template from www.brainybetty.com 10
HTML Example<html><head><title>Title</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../style/framework.css" rel="stylesheet" type="text/css"><script language="JavaScript" src="../script/framework/config.js"></script></head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">….…..….</body></html>
04/12/23 Free template from www.brainybetty.com 11
HTML Specification
• Referencehttp://www.w3.org/TR/html4/
• Maintain by
• Support Historyhttp://www.eskimo.com/~bloo/indexdot/html/supportkey/a.htm
04/12/23 Free template from www.brainybetty.com 12
How does it work?
BrowserBrowser
HTTP Request
TCP/IP Packet
Network
04/12/23 Free template from www.brainybetty.com 13
How does it work?
ServerServer
HTTP Request
TCP/IP Packet
Network
HTML Output
HTTP Response
TCP/IP Packet
04/12/23 Free template from www.brainybetty.com 14
How does it work?
BrowserBrowser
Network
HTML Output
HTTP Response
TCP/IP Packet
04/12/23 Free template from www.brainybetty.com 15
Question
• If HTTP message is larger than TCP/IP packet’s max length, what will happen?
• Is it possible to have more than one web site in the same server? How does it work?
• How can we know the server’s IP address
04/12/23 Free template from www.brainybetty.com 16
TCP/IP
• Each TCP/IP connection– Source IP– Source Port– Destination IP– Destination Port
• Reliable transmission
• Establish connection before transmit
• More overhead than UDP
04/12/23 Free template from www.brainybetty.com 17
Virtual Host
• Multi domain name in one server
• Each domain name have their own content, files, resource and etc. separately
• Domain name come from HTTP Request message
• Where IP come from?
04/12/23 Free template from www.brainybetty.com 18
HTTP Persistent Connection
• Send multi HTTP Request in one connection
• Why?– Reduce overhead– Get response faster
04/12/23 Free template from www.brainybetty.com 19
HTTP Session State
• HTTP is a stateless protocol
• Web server implementation much easier and much more effective
• Dynamic content?
• Control session on application level
04/12/23 Free template from www.brainybetty.com 20
More detail about HTTP
• HTTP Header specificationhttp://en.wikipedia.org/wiki/List_of_HTTP_headers
• HTTP Status codehttp://en.wikipedia.org/wiki/List_of_HTTP_status_codes
• HTTP Compression– Reduce bandwidth– Use Content-Encoding
04/12/23 Free template from www.brainybetty.com 21
Server concept
ApplicationApplicationHTTP Request
HTTP Response
04/12/23 Free template from www.brainybetty.com 22
Server concept
Web ServerWeb Server
HTTP Request
Request parameter Server PageServer Page
Server PageServer PageServer PageServer Page
Server PageServer Page
Use URI pattern to select which page to run..
HTML Output
+
Response parameter
HTTP Response
04/12/23 Free template from www.brainybetty.com 23
E.g. JSP
Web ServerWeb Server
Server PageServer Page
Request Object
ResponseObject
04/12/23 Free template from www.brainybetty.com 24
URL
• Uniform Resource Locators (URLs) are strings that specify how to access network resources, such as HTML documents. They are part of the more general class of Universal Resource Identifiers (URIs). The most important use of URLs is in HTML documents to identify the targets of hyperlinks. When using a Web browser such as Netscape, every highlighted region has a URL associated with it, which is accessed when the link is activated by a mouse click. Relative URLs specify only a portion of the full URL - the missing information is inferred though the context of the source document.
04/12/23 Free template from www.brainybetty.com 25
Secure Socket Layer
• Secure Sockets Layer (SSL), are cryptographic protocols that provide secure communications on the Internet for such things as web browsing, e-mail, Internet faxing, instant messaging and other data transfers.
• URL pattern – https://• For HTTP, normally use port 443• More detail later
04/12/23 Free template from www.brainybetty.com 26
Web Cookies
• HTTP cookies, sometimes known as web cookies or just cookies, are parcels of text sent by a server to a web browser and then sent back unchanged by the browser each time it accesses that server. HTTP cookies are used for authenticating, tracking, and maintaining specific information about users, such as site preferences and the contents of their electronic shopping carts. The term "cookie" is derived from "magic cookie," a well-known concept in unix computing which inspired both the idea and the name of HTTP cookies.
04/12/23 Free template from www.brainybetty.com 27
Web Cookies
04/12/23 Free template from www.brainybetty.com 28
Session
• Normally manage by web server
• Use cookie to help keeping session id or session identifier
• Session timeout, unused data will be cleared from memory
04/12/23 Free template from www.brainybetty.com 29
Session
BrowserBrowser
Web ServerWeb Server
Session ID
Cookie
Session DataSession
DataSession DataSession
Data
BrowserBrowserSession
ID
Cookie
04/12/23 Free template from www.brainybetty.com 30
Question
• If we close browser, will the cookie disappear?
• Can we change value in cookie manually?
• How to open web site in a new session– Open new browser window?