Content Serving Static vs Dynamic Content Web Servers
Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2. 0 © 2006 Scott Miller, University of Victoria 1 9/17/2020
Static vs. Dynamic Content l Static Content: Content that only changes when the site administrator changes it – Web pages, CSS, frame based sites, etc. – Includes “Dynamic looking” sites that have Java. Script client-side handlers l Dynamic Content: Customized content based on user input – May be input from older session (via cookies) – Query data, DB lookups, Preferences (portal), Secure logins for commerce, etc. – Generated via Web Application © 2006 Scott Miller, University of Victoria 2 9/17/2020
Static vs. Dynamic Content l Web Server: Program (daemon) that listens for HTTP requests (on port 80) – Serves static HTML documents l File on a file system mapped to the server’s root – Calls Application Server as needed l Application Server: – Program called upon by a Web Server – Dynamically generates predefined content as its output l © 2006 HTML, XHTML, ASCII, etc. Scott Miller, University of Victoria 3 9/17/2020
Web Server – Little Bit ‘o Practical l Domains are simply directory structures “mapped” off the hard disk. http: //www. foo. org/ / cgi-bin img web © 2006 * cgi-bin would not be found! Scott Miller, University of Victoria Hard drive note 4 9/17/2020
Web Server – Little Bit ‘o Practical l Virtual Hosting – The Web Server is configured to read a different directory structure as a domain’s root. http: //www. tim. biz/ http: //www. ryan. biz/ ryan / img tim © 2006 Scott Miller, University of Victoria Hard drive note 5 9/17/2020
Get to know your UNIX! l *NIX permissions are an effective shield against content others shouldn’t have. – Resources posted, but not yet available to user Know your directory structure for web serving (know what structure you will use to host site(s) and where to locate it/them. l Know how to edit remotely via command line – especially know basic vi. l © 2006 Scott Miller, University of Victoria 6 9/17/2020
Client-Server Web Server Interaction stdin CGI Request HTTP Web Server HTTP Response HTML, text, Java, etc. © 2006 Scott Miller, University of Victoria App Server CGI stdout HTML, text, Java, etc. 7 9/17/2020
Web Server Content HTML, CSS, XHTML, etc. l Binary files (any binaries to be downloaded) l Java Applets l Java. Script enabled content l Media rendering directly from MIME Types l © 2006 Scott Miller, University of Victoria 8 9/17/2020
Bandwidth management l Client side scripting: – ex. Text viewer (zoomed in) for visually impaired l Let them scroll around and zoom on client side after getting document from server Caching: Only get a resource if it has changed l Compression: Transmit less bits through compression l © 2006 Scott Miller, University of Victoria 9 9/17/2020
Dynamic Content Serving CGI Rev 2. 0 © 2006 Scott Miller, University of Victoria 10 9/17/2020
Application Servers l If a Web Server only hosts static content, how do we get dynamic content? – APPLICATION SERVER! Usually a plug-in to a web server; still a distinct program l Communicates with web server to perform calculations or action and return result l Can consist of any language l © 2006 Scott Miller, University of Victoria 11 9/17/2020
Server-Server communications stdin CGI Request HTTP Web Server HTTP Response HTML, text, Java, etc. © 2006 Scott Miller, University of Victoria App Server CGI stdout HTML, text, Java, etc. 12 9/17/2020
CGI – Common Gateway Interface l CGI is a protocol – Can be written in any language that can read from stdin, write to stdout and can read environment variables l l TRANSLATION: Pretty much any language you like Referenced in url – e. g. As a directory /cgi-bin/ l Launched from web server as a separate process to handle the request © 2006 Scott Miller, University of Victoria 13 9/17/2020
CGI Protocol l How does web server pass information to the application server? – Environment variables – stdin/stdout l CGI is about sending back the “Request Context” to the application server – HTTP request – HTTP headers – parameters © 2006 Scott Miller, University of Victoria 14 9/17/2020
CGI Protocol – HTTP Headers © 2006 HTTP Header Environment Variable Content-Length CONTENT_LENGTH Content-Type CONTENT_TYPE User-Agent HTTP_USER_AGENT Host HTTP_HOST * HTTP_* Scott Miller, University of Victoria 15 9/17/2020
CGI Protocol- Example GET /cgi-bin/Login. pl? username=Scott&pwd=foo HTTP/1. 1 Host: www. uvic. ca Cookie: login. Attempt=3 Cookie: config=1 <rn> Env. Variable HTTP_Host QUERY_STRING Value www. uvic. ca username=Scott&pwd=foo HTTP_COOKIE login. Attempt=3; config=1 © 2006 Scott Miller, University of Victoria 16 9/17/2020
CGI Protocol – Continued l The body of a HTTP request is written to stdin of the CGI process – POST method: body contains the query parameters l THEREFORE: CGI script must look query parameters in 2 places – If GET: QUERY_STRING – If POST: stdin will contain CONTENT_LENGTH bytes © 2006 Scott Miller, University of Victoria 17 9/17/2020
CGI Protocol – Finishing Touches l The CGI program writes the full HTTP response to stdout – Includes HTTP headers – In Other Words: Output of CGI program is a complete HTTP response © 2006 Scott Miller, University of Victoria 18 9/17/2020
CGI Calling l Each CGI process is created from scratch by the web server for each request – Environment variables are ONLY for one request – CGI process terminates once it is done writing output © 2006 Scott Miller, University of Victoria 19 9/17/2020
CG-I-Don’t-Know-About-This… l Having to output raw HTML in CGI programs is: 1. A maintenance nightmare!!! 2. No separation of content from presentation – 1 & 2 distinguish this approach as terrible Software Engineering. Why? l Doesn’t scale well – New process for EACH request © 2006 Scott Miller, University of Victoria 20 9/17/2020
CGI Key Ideas Output of CGI is HTML to be displayed on the browser l What HTML contains is determined when the program runs (DYNAMIC CONTENT) as a function of query parameters l In practice: the strings of HTML your CGI program generates will contain variables populated by queries l © 2006 Scott Miller, University of Victoria 21 9/17/2020
- Slides: 21