10. A brief glance
1. DNS
2. Send Request
3. Get Response
4. Render Page
11. Hypertext Transfer Protocol (HTTP)
The Hypertext Transfer
Protocol (HTTP) is a
networking protocol for
distributed, collaborative,
hypermedia information
systems.[1] HTTP is the
foundation of data
communication for the World
Wide Web.
33. HTTP
• Request message
– Request line, such as GET /images/logo.png HTTP/1.1, which requests a resource called
/images/logo.png from server
– Headers, such as Accept-Language: en
– An empty line
– An optional message body
• Request methods
– HEAD
– GET
– POST
– PUT
– DELETE
– TRACE
– OPTIONS
– CONNECT
• Status codes
• Cache
• …
The browser main functionality is to present the web resource you choose, by requesting it from the server and displaying it on the browser window. The resource format is usually HTML but also PDF, image and more. The location of the resource is specified by the user using a URI (Uniform resource Identifier).Basic features for browser:Download pageRender pageGood performanceCross OSUI
The user interface - this includes the address bar, back/forward button, bookmarking menu etc. Every part of the browser display except the main window where you see the requested page.The browser engine - the interface for querying and manipulating the rendering engine.The rendering engine - responsible for displaying the requested content. For example if the requested content is HTML, it is responsible for parsing the HTML and CSS and displaying the parsed content on the screen.Networking - used for network calls, like HTTP requests. It has platform independent interface and underneath implementations for each platform.UI backend - used for drawing basic widgets like combo boxes and windows. It exposes a generic interface that is not platform specific. Underneath it uses the operating system user interface methods.JavaScript interpreter. Used to parse and execute the JavaScript code.Data storage. This is a persistence layer. The browser needs to save all sorts of data on the hard disk, for examples, cookies. The new HTML specification (HTML5) defines 'web database' which is a complete (although light) database in the browser.It is important to note that Chrome, unlike most browsers, holds multiple instances of the rendering engine - one for each tab,. Each tab is a separate process.
WebKit: SafariGecko: FirefoxTrident: IE
Notice:new_socket = accept(listen_socket, …) read(new_socket, …)Both parent and child process should close socket which is not use anymore.fork (vfork) vs clonePrefork modes:Master listen, workers accept without mutexMaster listen, workers accept with mutexMaster listen and accept, communicate to workers
Two phrases of read socket:1. Kernel buffer is ready2. Copy kernel buffer to user spaceEvent Demultiplexer:Reactor pattern: When Kernel buffer is ready, Demultiplexer call user’s handler to do read/write operationProactor pattern: When Kernel finish read/write operations, Demultiplexer call user’s handler passing into io result to do other works.Good resource: “ACE network programming”
Concept:A bridge connecting http server and application processor (followedcgi)Popular languages as cgi:C, shell, perl, vbMain flow:Fork and executeDraw back: low performanceExample: bugzilla
Useage:Load balanceReverse proxyAdvantages:StableSeparate IO process and logic processMulti languages
Apache + php work flow:When starts, apache loads all libraries and execute MINIT.When request arrives, PHP call RINIT for all modules to initialize environment for response.After sends reply, PHP call RSHUTDOWN to clear environment.MSHUTDOWN will be called for all modules in each process forked by apache before apache closing.