DOC PREVIEW
Princeton COS 318 - Building Your Very Own Web Server

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Fun Fun Project OneWhat is a Web Server?A Simplified Web ServerWhat Does “Connect” Mean?How Do You Identify MachinesHow Do You Identify Files?What’s In A Request Message?What Do You Care About?What Could They Want?What’s In A Response Message?What’s a Minimal Response?Response when…How to Test Your Server?More Test CasesWhat is Content-Type?Need more info?Why open instead of fopen?What’s a File Descriptor?General StepsWhat Am I Given?Help! I’m Lost!Why Are We Doing This?Wrap UpFun Fun Project One 1Fun Fun Project OneBuilding Your Very Own Web ServerFun Fun Project One 2What is a Web Server?Program that understands the HTTP protocol and generates appropriate responsesClients “connect” to the machineClients send a “request”Server reads request, generates “response”Client interprets response appropriatelyFun Fun Project One 3A Simplified Web ServerClient asks for fileServer finds appropriate fileServer sends back a response header followed by the requested file’s dataServer closes connectionFun Fun Project One 4What Does “Connect” Mean?For all practical purposes, it looks like there’s data available via a file descriptorStream of bytesCan be treated like any other file descriptorNot a FILE * (like stdio, stderr)Must use read() and write() system callsFun Fun Project One 5How Do You Identify MachinesDomain names/IP address and portshttp://www.cs.princeton.edu implies a machine named www.cs.princeton.edu and a default port of 80http://127.0.0.1:8080/index.htmlRefers to local box (127.0.0.1 is me)Port # is 8080 (used for this project)File is named index.htmlFun Fun Project One 6How Do You Identify Files?File name is specified in Request MessageServer maps that name to a real fileMapping can be done in whichever way server wantsFor example, /~vivek/index.html is actually /n/fs/fac/vivek/public_html/index.htmlIn your web server, you can choose your ownFun Fun Project One 7What’s In A Request Message?GET /index.html HTTP/1.0\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/4.72 [en] (X11..)\r\nHost: 127.0.0.1:31415\r\nAccept: image/gif, image/jpeg, */*\r\nAccept-Encoding: gzip\r\nAccept-Language: en\r\nAccept-Charset: iso-8859-1,*,utf-8\r\n\r\nFun Fun Project One 8What Do You Care About?GET /index.html HTTP/1.0In particular, just index.htmlAssume “/” means “/index.html”Fun Fun Project One 9What Could They Want?An honest-to-goodness file (me.jpg)An indirect request for such a file (such as “/” meaning index.html)An implied directory with index (/home/vivek instead of /home/vivek/)Just a directory listingA query (we don’t care about these)An invalid/nonexistent fileFun Fun Project One 10What’s In A Response Message?HTTP/1.0 200 OK\r\nDate: blah-blah-blah\r\nServer: blah-blah-blah\r\nContent-Type: important\r\nContent-Length: 12345\r\nLast-Modified: blah-blah-blah\r\n\r\nRaw dataFun Fun Project One 11What’s a Minimal Response?HTTP/1.0 200 OK\r\nContent-Type: stuff\r\n\r\nDataHTTP/1.0 302 Moved\r\nLocation: newurl\r\n\r\nHTTP/1.0 404 Not Found\r\n\r\nBut alsoConnection: close\r\nContent-Length: yyy\r\nFun Fun Project One 12Response when… File exists? Send itDirectory without “/” suffix? RedirectDirectory with index.html? Send itDirectory with no index.html? List itFor each list entry, add “/” if neededFailure(Not Found)? Send 404Bad Request? Send 400Fun Fun Project One 13How to Test Your Server?Use a browser(Netscape/IE)Use “wget”Support HTTP protocolhttp://www.gnu.org/manual/wgetcreate directory hierarchy for retrievingInclude some big imagesFun Fun Project One 14More Test CasesWhat if Request Message is not send/received in one packet…The server must read all the Request Messages before it gives any response messageRemember the double carriage return and line feed?Your web server must consider this!I’ll distribute more test programs later on, check http://www.cs.princeton.edu/~yongwang/cos318Fun Fun Project One 15What is Content-Type?text/htmlimage/gifimage/jpeg(Other types not needed for project 1.)Fun Fun Project One 16Need more info? HTTP 1.1 Specification – RFC2068HTTP 1.0 – RFC 1945man pagesman manman –k blahread( ), write( ), open( ), close( )Fun Fun Project One 17Why open instead of fopen?Compare fopen, fread, etc., with open, read, etcWe’re dealing with functions closer to the OS – easier to use in some casesFun Fun Project One 18What’s a File Descriptor?Sort of like a FILE *It’s an integer provided by OSUsed to represent a stream of bytesCan represent file or network connectionBehavior is slightly differentEspecially when reading/writing networkFun Fun Project One 19General StepsSetup, and thenGet next connectionIf file, read from diskIf directory, generate listingSend all to clientClose connection, wait for next one(nonpersistent connection)Fun Fun Project One 20What Am I Given?Setup functionMakes server available for connectionsAccept functionGets a connection from a clientFile type functionTells you what kind of file, if it existsTells you how many bytes if a regular fileDirectory listing functionsGives you the file names one at a timeFun Fun Project One 21Help! I’m Lost!Don’t know HTML? Use Netscape composer to see what to doView page source for various pagesDo “telnet www.domain.com 80” and issue the GET manually (need to add “Host: www.domain.com” header)AskFun Fun Project One 22Why Are We Doing This?Infrastructure for future projectsSome OS/Networking interactionIt’s fun, and not too badFun Fun Project One 23Wrap UpThanks!Q&A session next week!Office Hour: Wed


View Full Document

Princeton COS 318 - Building Your Very Own Web Server

Documents in this Course
Overview

Overview

25 pages

Deadlocks

Deadlocks

25 pages

lectute 2

lectute 2

28 pages

Lecturel

Lecturel

24 pages

Real mode

Real mode

49 pages

Lecture 2

Lecture 2

54 pages

lecture 5

lecture 5

27 pages

Load more
Download Building Your Very Own Web Server
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Building Your Very Own Web Server and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Building Your Very Own Web Server 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?