An Example of a TCP/IP Application: the World Wide Web

Slides:



Advertisements
Similar presentations
DT228/3 Web Development WWW and Client server model.
Advertisements

Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
The Application Layer Chapter 7. Electronic Mail Architecture and Services The User Agent Message Formats Message Transfer Final Delivery.
Introduction to Web Based Application. Web-based application TCP/IP (HTTP) protocol Using WWW technology & software Distributed environment.
And so on CGI programming Web Services Java Programs for the Web.
The World Wide Web and the Internet Dr Jim Briggs 1WUCM1.
Definitions, Definitions, Definitions Lead to Understanding.
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.
Hypertext Transport Protocol CS Dick Steflik.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
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.
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.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
HTTP; The World Wide Web Protocol
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
A Closer Look at HTTP HyperText Transfer Protocol.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web 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.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
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.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Http protocol Response-request Clients not limited to web browsers. Anything that can access code implementing the protocol works: –Standalone programs.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Form Data Encoding GET – URL encoded POST – URL encoded
Netprog 2002 CGI Programming1 CGI Programming CLIENT HTTP SERVER CGI Program http request http response setenv(), dup(), fork(), exec(),...
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
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.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 22 World Wide Web and HTTP.
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)
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
CS299: Web Programming and Design Instructor: Dr. Fang (Daisy) Tang
Hypertext Transfer Protocol
Section 6.3 Server-side Scripting
WWW and HTTP King Fahd University of Petroleum & Minerals
Hypertext Transfer Protocol
CGI I: Basics Web Programming.
Introduction to CGI and ajax
Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Hypertext Transport Protocol
CGI CS422 Dick Steflik.
Tutorial (4): HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Simple PHP application
Introduction to CGI and ajax
DT211/3 Internet Development Application
Chapter 27 WWW and HTTP.
Introduction to Servlets
HyperText Transfer Protocol
What is Perl? PERL--Practical Extraction and Report Language
Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
The HTTP Protocol COSC 2206 Internet Tools The HTTP Protocol
World Wide Web Components
CGI I: Basics Web Programming.
Presentation transcript:

An Example of a TCP/IP Application: the World Wide Web Babak Esfandiari (plus some material by Qusay Mahmoud, Roger Impey, and the textbooks)

The World Wide Web No need to introduce the Web, is there? A uniform resource locator: URL A protocol: HTTP The client: a Web browser The server: the Web server A markup language: HTML Server-side dynamic generation of HTML documents: CGI, Servlets, ASPs, JSPs… Client-side rendering: Stylesheets, JavaScript, Java, Flash…

WWW Architecture

HTTP Hypertext Transport Protocol Client/server Transaction-oriented Not limited to hypertext though! Client/server Transaction-oriented Stateless

The Uniform Resource Locator (URL) Not limited to HTTP: protocol://host:port/resource_path The browsers default to: http protocol Port 80 Index.html resource Resources can be static or dynamic

The HTTP Protocol RFCs 1945 and 2068 for versions 1.0 and 1.1 respectively HTTP transactions consist in a request and a response Two types of request methods: GET and POST

GET Request Simple get request: (HTTP 0.9) Full get request: GET /document.html [CRLF] Full get request: GET /document.html HTTP/1.0 [CRLF] Full get request with headers: If-Modified-Since: Sun 20 Oct 1996 04:07:51 GMT[CRLF] [LF]

Post request Post allows the client to include a body of data in a request: POST /cgi-bin/code.cgi HTTP/1.0 [CRLF] Content-type: application/octet-stream [CRLF] Content-length: 2048 [CRLF] [LF] body

HTTP Responses Simple Response: body Full Response: HTTP/1.0 200 OK[CRLF] [LF] body Full Response with headers: Content-type: text/html[CRLF]

HTTP Response codes Here a few response codes: OK Bad Request Unauthorized Not Found Internal Server Error

MIME types Originally designed for email, associates a type with a message to help the receiver to decode/view (RFC 1521) Can be used in a HTTP header Type/subtype Common types/subtypes: text/html, text/plain, image/gif…

A simple HTTP Server See textbook!

Programming Web Applications CGI Servlets JSP What do these have in common? They are all server-side technologies!

CGI What is CGI How does it work? Environment variables Processing Forms GET vs. POST Examples

What is CGI? Stands for “Common Gateway Interface” Server-side technology Can be used: To Process fill-out forms To generate dynamic contents By a web server to run external programs By a web server to get/send data from databases and other apps

How does it work? HTTP Receive Request CGI Process Fork Process Gen. Response Receive Output Send Response

CGI CGI scripts can be written in any language, including Java Perl is the most popular for CGI scripting To experiment, you need a web server: Xitami (www.xitami.com) Jakarta-Tomcat (jakarta.apache.org/tomcat) Tomcat supports Servlets/JSP

Content-type: text/html\n\n Content headers If your script generates HTML then use: Content-type: text/html\n\n This tells the browser what content it is about to receive Other content headers (MIME!) include: text/plain image/gif image/jpg

Sample Script #!/usr/bin/perl print "Content-type:text/html\n\n"; print "<html><head><title>Test Page</title></head>\n"; print "<body>\n"; print "<h2>Hello, world!</h2>\n"; print "</body></html>\n";

Environment Variables Some of the environment variables: DOCUMENT_ROOT HTTP_HOST HTTP_USER_AGENT REMOTE_HOST REQUEST_METHOD QUERY_STRING CONTENT_LENGTH …etc

Script: environment variables #!/usr/bin/perl print "Content-type:text/html\n\n"; print <<EndOfHTML; <html><head><title>Print Environment</title></head> <body> EndOfHTML foreach $key (sort(keys %ENV)) { print "$key = $ENV{$key}<br>\n"; } print "</body></html>";

Forms <form action="env.cgi" method="GET"> Enter some text here: <input type="text" name="sample_text" size=30><input type="submit"><p> </form>

Forms As you know now, there are two ways to send data from an HTML form to a CGI script GET POST These methods determine how the form data is sent to the server

GET The input values from the form are sent as part of the URL They are saved in the QUERY_STRING environment variable If in the above example you type: “hello there John” The QUERY_STRING will be: Sample_text=hello+there+John Spaces have been replaced with +

GET…. This is called URL Encoding! Some commonly encoded characters \t (tab) %09 \n (return) %0A / %2F ~ %7E : %3A ; %3B @ %40 & %26

GET…. If input is: Sarah Johnson <form action="env.cgi" method="GET"> First Name: <input type="text" name="fname“ size=30><p> Last Name: <input type="text" name="lname" size=30><p> <input type="submit"> </form> If input is: Sarah Johnson $ENV{‘QUERY_STRING’} would be: fname=Sarah&lname=Johnson

GET…. Parsing: @values = split(/&/,$ENV{'QUERY_STRING'}); foreach $i (@values) { ($varname, $mydata) = split(/=/,$i); print "$varname = $mydata\n"; }

GET…. It is possible to send values as part of a URL Hidden values can be used to maintain session info

POST More sophisticated than GET Data is not sent as URL-encoded (I.e. not part of the URL) When POST is used, data is sent as a separate message (input stream)

POST…. Parsing: read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; }