10/13/2015 ©2006 scott miller, university of victoria 1 content serving static vs. dynamic content...

21
06/27/22 ©2006 Scott Miller, University of Victoria 1 Content Serving Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

Upload: shauna-lawson

Post on 13-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria1

Content ServingContent ServingStatic vs. Dynamic ContentWeb ServersServer Flow Control

Rev. 2.0

Page 2: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria2

Static vs. Dynamic ContentStatic vs. Dynamic Content

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

JavaScript client-side handlers 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

Page 3: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria3

Static vs. Dynamic Content Static vs. Dynamic Content

Web Server: Program (daemon) that listens for HTTP requests (on port 80)– Serves static HTML documents

File on a file system mapped to the server’s root

– Calls Application Server as needed Application Server:

– Program called upon by a Web Server

– Dynamically generates predefined content as its output

HTML, XHTML, ASCII, etc.

Page 4: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria4

Web Server – Little Bit ‘o Web Server – Little Bit ‘o PracticalPracticalDomains are simply directory structures

“mapped” off the hard disk.

//

webwebimgimg

notenote

cgi-bincgi-binHard drive

http://www.foo.org/ * cgi-bin would not be found!

Page 5: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria5

Web Server – Little Bit ‘o Web Server – Little Bit ‘o PracticalPracticalVirtual Hosting – The Web Server is

configured to read a different directory structure as a domain’s root.

//

timtimimgimg

notenote

ryanryan

Hard drive

http://www.tim.biz/ http://www.ryan.biz/

Page 6: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria6

Get to know your UNIX!Get to know your UNIX!

*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.

Know how to edit remotely via command line – especially know basic vi.

Page 7: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria7

Client-Server Web Server Client-Server Web Server InteractionInteraction

WebServer

AppServer

HTTP CGI

stdin

HTTP

Request

CGIstdoutResponse

HTML, text, Java, etc. HTML, text, Java, etc.

Page 8: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria8

Web Server ContentWeb Server Content

HTML, CSS, XHTML, etc.Binary files (any binaries to be

downloaded)Java AppletsJavaScript enabled contentMedia rendering directly from MIME

Types

Page 9: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria9

Bandwidth managementBandwidth management

Client side scripting:– ex. Text viewer (zoomed in) for visually

impairedLet them scroll around and zoom on client side

after getting document from serverCaching: Only get a resource if it has

changedCompression: Transmit less bits through

compression

Page 10: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria10

Dynamic Content ServingDynamic Content ServingCGI

Rev 2.0

Page 11: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria11

Application Servers Application Servers

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

Communicates with web server to perform calculations or action and return result

Can consist of any language

Page 12: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria12

Server-Server communicationsServer-Server communications

WebServer

AppServer

HTTP CGI

stdin

HTTP

Request

CGIstdoutResponse

HTML, text, Java, etc. HTML, text, Java, etc.

Page 13: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria13

CGI – Common Gateway CGI – Common Gateway InterfaceInterfaceCGI is a protocol

– Can be written in any language that can read from stdin, write to stdout and can read environment variables

TRANSLATION: Pretty much any language you like

Referenced in url– e.g. As a directory /cgi-bin/

Launched from web server as a separate process to handle the request

Page 14: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria14

CGI ProtocolCGI Protocol

How does web server pass information to the application server?– Environment variables– stdin/stdout

CGI is about sending back the “Request Context” to the application server– HTTP request– HTTP headers– parameters

Page 15: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria15

CGI Protocol – HTTP HeadersCGI Protocol – HTTP Headers

HTTP Header Environment Variable

Content-Length CONTENT_LENGTH

Content-Type CONTENT_TYPE

User-Agent HTTP_USER_AGENT

Host HTTP_HOST

* HTTP_*

Page 16: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria16

CGI Protocol- ExampleCGI Protocol- ExampleGET /cgi-bin/Login.pl?username=Scott&pwd=foo HTTP/1.1Host: www.uvic.caCookie: loginAttempt=3Cookie: config=1<\r\n>

Env. Variable ValueHTTP_Host www.uvic.ca

QUERY_STRING username=Scott&pwd=foo

HTTP_COOKIE loginAttempt=3;config=1

Page 17: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria17

CGI Protocol – ContinuedCGI Protocol – Continued

The body of a HTTP request is written to stdin of the CGI process– POST method: body contains the query

parametersTHEREFORE: CGI script must look

query parameters in 2 places– If GET: QUERY_STRING– If POST: stdin will contain

CONTENT_LENGTH bytes

Page 18: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria18

CGI Protocol – Finishing CGI Protocol – Finishing TouchesTouchesThe CGI program writes the full HTTP

response to stdout– Includes HTTP headers– In Other Words: Output of CGI program is a

complete HTTP response

Page 19: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria19

CGI CallingCGI Calling

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

Page 20: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria20

CG-I-Don’t-Know-About-This…CG-I-Don’t-Know-About-This…

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? Doesn’t scale well

– New process for EACH request

Page 21: 10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0

04/21/23©2006 Scott Miller, University of Victoria21

CGI Key IdeasCGI Key Ideas

Output of CGI is HTML to be displayed on the browser

What HTML contains is determined when the program runs (DYNAMIC CONTENT) as a function of query parameters

In practice: the strings of HTML your CGI program generates will contain variables populated by queries