Lecture 9, 20-755: The Internet, Summer 1999 1 20-755: The Internet Lecture 9: Web Services II David O’Hallaron School of Computer Science and Department.

Slides:



Advertisements
Similar presentations
CGI & HTML forms CGI Common Gateway Interface  A web server is only a pipe between user-agents  and content – it does not generate content.
Advertisements

Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
How does the server format the information it gives to the appln program? As environment variables and in standard input.
Pass data1 Passing data from an HTML page to a program Dr Jim Briggs.
Web Services Nov 26, 2002 Topics HTTP Serving static content Serving dynamic content class27.ppt “The course that gives CMU its Zip!”
Guide To UNIX Using Linux Third Edition
Outcomes Know what are CGI Environment Variables Know how to use environment variables How to process A simple Query Form Able to use URL Encoding rules.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
Client, Server, HTTP, IP Address, Domain Name. Client-Server Model Client Bob Yahoo Server yahoo.com/finance.html A text file named finance.html.
CGI. CGI Programming What is "CGI"? –Common Gateway Interface A means of running an executable program via the Web. CGI is not a Perl-specific concept.
Internet Services II April 27, 2000 Topics dynamic content Tiny Web server tour class28.ppt.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Sockets and Web services April 23, 2002 Topics Client-server model Sockets Interface HTTP Serving static content Serving dynamic content Reading 12.7,
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
Common Gateway Interface
1 ‘Dynamic’ Web Pages So far, we have developed ‘static’ web-pages, e.g., cv.html, repair.html and order.html. There is often a requirement to produce.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
Overview A plain HTML document is static A CGI program is executed in real-time, so that it can output dynamic information. CGI (Common Gateway Interface)
CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
Networking Programming --Web Server(I) 1. Outline Web History Web Servers –HTTP Protocol –Web Content –CGI Suggested Reading: –
Web Services Topics HTTP Serving static content
Web Server Design Week 14 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/14/10.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
USING PERL FOR CGI PROGRAMMING
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
Lecture 21 Common Gateway Interface CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
CSCE Systems Programming Lecture 21 Web Server: CGI -Dynamic Pages CSCE March 25, 2013.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Chapter 9: Perl and CGI Programming CGI Programming Acknowledgement: Some materials are taken from Teach Yourself CGI Programming with PERL 5 in a Week.
Chapter 6 Server-side Programming: Java Servlets
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Perl: Lecture 2 Advanced RE & CGI. Regular Expressions 2.
Perl CGI What is "CGI"? Common Gateway Interface A means of running an executable program via the Web. Perl have a *very* nice interface to create CGI.
Form Data Encoding GET – URL encoded POST – URL encoded
Introduction to Programming the WWW I CMSC Winter 2003.
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
Netprog 2002 CGI Programming1 CGI Programming CLIENT HTTP SERVER CGI Program http request http response setenv(), dup(), fork(), exec(),...
Web Services November 30, 2004 Topics HTTP Serving static content Serving dynamic content “The course that gives CMU its Zip!” class26.ppt.
Web Services. 2 Internet Collection of physically interconnected computers. Messages decomposed into packets. Packets transmitted from source to destination.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
EE 122: Lecture 21 (HyperText Transfer Protocol - HTTP) Ion Stoica Nov 20, 2001 (*)
Web Server Design Assignment #5: Unsafe Methods & CGI Due: 05/05/2010 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin.
CS 330 Class 8 Homework A pattern that contains a word with an optional period A pattern that contains Fred with a space (not Freddy) See regexp.txt guest4.htm.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
Pass data1 Passing data from an HTML page to a program Dr Jim Briggs.
Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2012 Michael L. Nelson 04/03/12.
Web Server Design Week 15 Old Dominion University Department of Computer Science CS 495/595 Spring 2009 Michael L. Nelson 4/20/09.
1 CGI (Common Gateway Interface) CmpE 587 Emir Bayraktar Onur Bük.
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
The Common Gateway Interface (CGI) Pat Morin COMP2405.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
CGI I: Basics Web Programming.
The HTTP Protocol COSC 2206 Internet Tools The HTTP Protocol
Environment Variables
An Example of a TCP/IP Application: the World Wide Web
HTTP Hypertext Transfer Protocol
Web Server Design Week 16 Old Dominion University
CGI I: Basics Web Programming.
Presentation transcript:

Lecture 9, : The Internet, Summer : The Internet Lecture 9: Web Services II David O’Hallaron School of Computer Science and Department of Electrical and Computer Engineering Carnegie Mellon University Institute for eCommerce, Summer 1999

Lecture 9, : The Internet, Summer Today’s lecture Dynamic content background (35 min) Break (10 min) Serving dynamic content with GET and POST (40 min)

Lecture 9, : The Internet, Summer How programs run other programs Recall that a process is an instance of a running program. Suppose a process A, which is running program foo, wants to run the program bar. Two-step procedure: –First, process A creates a new process B that is a clone of A »A and B are independent processes running concurrently on the machine. »A is the parent, B is the child. »Each has a unique process id (pid) –Second, process B recognizes that it is a clone, overwrites foo with bar, and transfers control to the first instruction in bar.

Lecture 9, : The Internet, Summer How programs run other programs Initially, foo is running in process A with process id (pid) of 325. foo Process A pid = 325

Lecture 9, : The Internet, Summer How programs run other programs Next, program foo running in process A clones a copy of itself. So now we have two identical independent processes (A and B) running the same code. A can wait immediately for B to complete, or do other work in the meantime. foo Process A foo Process B pid = 325 pid = 326

Lecture 9, : The Internet, Summer How programs run other programs The instance of foo in process B recognizes that it is a clone. Process B foo replaces its code with the code for bar. foo Process A bar Process B pid = 325 pid = 326

Lecture 9, : The Internet, Summer How programs run other programs pid = fork() –creates a clone of the current process. –returns a 0 to the child process. –returns the positive integer process ID of the child to the parent. exec(objfile) –replaces the current running program with the code in the executable file objfile. –exec never returns to the caller unless there is an error. »e.g., if it can’t locate objfile.

Lecture 9, : The Internet, Summer How programs run other programs # This is how program foo running in process A # runs program bar in a new process B # the parent executes this statement $child_pid = fork(); # both parent and child run the if statement if ($child_pid == 0) { # Only the child executes this code print “I’m the child\n” exec(bar); # the child only gets to this point if the # exec fails die “can’t exec bar: $!”; } # the parent continues here

Lecture 9, : The Internet, Summer Perl abstractions for fork and exec backquote operator –$output = `foo`; »runs the executable program foo and returns the contents of STDOUT to variable $output. system command –system(“foo”, $arg1, arg2); »runs executable program date. »output goes to wherever STDOUT is currently going (e.g., the screen) –system($prog > mydate.txt”) »redirects output to file mydate.txt

Lecture 9, : The Internet, Summer How programs pass info to the programs they create Command line arguments –the exec operator can pass a list of ASCII arguments to the program that it run »exec(“foo.pl”, “dave”, “ohallaron”); #!/usr/local/bin/perl5 -w # holds the arguments. # returns the number of array elements # $0 is the name of the perl script (foo.pl) # $ARGV[0] is the first array element (argument) # $ARGV[1] is the second array element (argument) if != 2) { print "usage: $0 first last\n"; exit; } print "arg0 = $ARGV[0]\n"; # dave print "arg1 = $ARGV[1]\n"; # ohallaron

Lecture 9, : The Internet, Summer How programs pass info to the programs they create Environment variables –Each process maintains a set of “environment variables” »list of ASCII (name,value) pairs. »represent long term conditions or preferences. –A forked process gets an exact duplicate of the parent’s environment variables.

Lecture 9, : The Internet, Summer Unix shell environment variables % printenv PWD=/usr/droh/afs/ TERM=emacs EMACS=t MANPATH=/usr/man:/usr/local/man:/usr/local/apache/man:/usr/X11R6/man PRINTER=iron login_done=1 HOSTNAME=kittyhawk.cmcl.cs.cmu.edu HOSTTYPE=i386_linux3 HOST=kittyhawk.cmcl.cs.cmu.edu SHLVL=2 KRBTKFILE=/tkt/ d-379b6ada PATH=.:/usr/droh/bin:/usr/sbin:/sbin:/usr/local/apache/bin: /usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/etc:/etc: /usr/X11R6/bin USER=droh SHELL=/usr/local/bin/tcsh HOME=/usr/droh

Lecture 9, : The Internet, Summer Accessing environment variables from PERL Environment variables stored in a special hash called “%ENV” # sort and list the environment variables foreach $key(sort keys %ENV) { print “$key=$ENV{$key}\n”; } # add a new (key,value) pair to the environment hash %ENV{“IPADDR”} = “ ”; # delete a (key,value) pair from the environment hash delete $ENV{“IPADDR”};

Lecture 9, : The Internet, Summer Serving dynamic content clientserver Client sends request to server. If request URI contains the string “/cgi-bin”, then the server assumes that the request is for dynamic content. GET /cgi-bin/env.pl HTTP/1.1

Lecture 9, : The Internet, Summer Serving dynamic content clientserver The server creates a child process and runs the program identified by the URI in that process env.pl fork/exec

Lecture 9, : The Internet, Summer Serving dynamic content clientserver The child runs and generates the dynamic content. The server captures the content of the child and forwards it without modification to the client env.pl content

Lecture 9, : The Internet, Summer Serving dynamic content clientserver The child terminates. Server waits for the next client request.

Lecture 9, : The Internet, Summer Issues in serving dynamic content How does the client pass program arguments to the server? How does the server pass these arguments to the child? How does the server pass other info relevant to the request to the child? How does the server capture the content produced by the child? These issues are addressed by the Common Gateway Interface (CGI) specification. clientserver content request create env.pl

Lecture 9, : The Internet, Summer Break time! Fish

Lecture 9, : The Internet, Summer Today’s lecture Dynamic content background (35 min) Break (10 min) Serving dynamic content with GET and POST (40 min)

Lecture 9, : The Internet, Summer Issues in serving dynamic content How does the client pass program arguments to the server? How does the server pass these arguments to the child? How does the server pass other info relevant to the request to the child? How does the server capture the content produced by the child? These issues are addressed by the Common Gateway Interface (CGI) specification. clientserver content request create env.pl

Lecture 9, : The Internet, Summer CGI Because the children are written according to the CGI spec, they are often called CGI programs. –Because many CGI programs are written in Perl, they are often called CGI scripts. However, CGI really defines a simple standard between the client (browser), the server, and the child process.

Lecture 9, : The Internet, Summer add.com: THE Internet addition service! Ever needed to add two numbers together and you just can’t find your calculator? Try Dr. Dave’s addition service at add.com! –Takes as input your name, and two numbers you want to add together. –Returns their sum in a tasteful personalized message. –After the IPO we’ll expand to multiplication!

Lecture 9, : The Internet, Summer Serving dynamic content with GET Question: How does the client pass arguments to the server? Answer: The arguments are appended to the URI Can be encoded directly in a URL typed to a browser or a URL in an HTML link – –add.pl is the program on the server that will do the addition. –argument list starts with “?” –arguments separated by “&” –spaces represented by “+” Can also be generated by an HTML form

Lecture 9, : The Internet, Summer Serving dynamic content with GET URL: – Result: Mr. Dave O'Hallaron, Welcome to add.com! The answer is: = 3 Please come again soon! Tell your friends!

Lecture 9, : The Internet, Summer Serving dynamic content with GET Question: How does the server pass these arguments to the child? Answer: In environment variable QUERY_STRING –a single string containing everything after the “?” –for add.com: QUERY_STRING = “Dave+O’Hallaron&1&2” # # Child code that parses the add.com arguments # $args = $ENV{QUERY_STRING}; $args =~ s/\+/ /; #replaces + with “ “ ($name, $a1, $a2) = split(/&/, $args);

Lecture 9, : The Internet, Summer Serving dynamic content with GET Question: How does the server pass other info relevant to the request to the child? Answer: in a collection of environment variables defined by the CGI spec.

Lecture 9, : The Internet, Summer Some CGI environment variables General –SERVER_SOFTWARE –SERVER_NAME –GATEWAY_INTERFACE (CGI version) Request specific –SERVER_PORT –REQUEST_METHOD (GET, POST, etc) –QUERY_STRING (contains args) –REMOTE_HOST (domain name of client) –REMOTE_ADDR (IP address of client) –CONTENT_TYPE (for POST, type of data in message body, e.g., text/html) –CONTENT_LENGTH (length in bytes)

Lecture 9, : The Internet, Summer Some CGI environment variables In addition, the value of each header of type type received from the client is placed in environment variable HTTP_type –Examples: »HTTP_ACCEPT »HTTP_HOST »HTTP_USER_AGENT (any “-” is changed to “_”)

Lecture 9, : The Internet, Summer Serving dynamic content with GET Questions: How does the server capture the content produced by the child? Answer: The child writes its content to stdout. # # server code that runs child and captures stdout # # run the child and put its dynamic content in $child_output $child_output = `add.pl`; # send the child’s dynamic content back to the client $connfd->print($output)

Lecture 9, : The Internet, Summer Putting it all together: The CGI script for GET requests to add.com #!/usr/local/bin/perl5 $args = $ENV{QUERY_STRING}; $args =~ s/\+/ /; ($name, $a1, $a2) = split(/&/, $args); print "Content-type: text/html\n\n"; print " \n"; print " Mr. $name, Welcome to add.com! \n"; print " The answer is: $a1 + $a2 = ", $a1+$a2, " \n"; print " Please come again soon! Tell your friends! \n"; print " \n";

Lecture 9, : The Internet, Summer Serving dynamic content with POST More complicated and less general than GET Less frequently used because of the complexity. Only advantage is that it provides arbitrary- length argument lists –older browsers and servers had unnecessary limits on URI lengths in GET requests –doesn’t seem to be a problem anymore

Lecture 9, : The Internet, Summer Serving dynamic content with POST Question: How does the client pass arguments to the server? Answer: In the message body of the HTTP request generated by a form. –space converted to “+” –puctuation converted to “%asciihexvalue” »e.g., apostrophe becomes “%27”

Lecture 9, : The Internet, Summer add.com HTML form (form.html) Name num1 num2

Lecture 9, : The Internet, Summer HTTP request generated by add.com form POST /cgi-bin/post.pl HTTP/1.1 Accept: */* Referer: Accept-Language: en-us Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 98) Host: add.com Content-Length: 34 CRLF name=Dave+O%27Hallaron&num1=1&num2=2

Lecture 9, : The Internet, Summer Serving dynamic content with POST Questions: How does the server pass the arguments to the child? Answer: Arguments are passed as one line via stdin.

Lecture 9, : The Internet, Summer Serving dynamic content with POST Question: How does the server pass other info relevant to the request to the child? Answer: As with GET, in a collection of environment variables defined by the CGI spec. Question: How does the server capture the content produced by the child? Answer: As with GET, via stdout.