ImageVerifierCode 换一换
格式:PPT , 页数:41 ,大小:163.50KB ,
资源ID:380269      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-380269.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(20-755- The InternetLecture 10- Web Services III.ppt)为本站会员(terrorscript155)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

20-755- The InternetLecture 10- Web Services III.ppt

1、20-755: The Internet Lecture 10: Web Services III,David OHallaron School of Computer Science and Department of Electrical and Computer Engineering Carnegie Mellon UniversityInstitute for eCommerce, Summer 1999,Todays lecture,Anatomy of a simple Web server (40 min) Break (10 min) Advanced server feat

2、ures (45 min),Anatomy of Tiny: A simple Web server,#!/usr/local/bin/perl5 -w use IO:Socket; # # tiny.pl - The Tiny HTTP server #,Tiny: configuration,# # Configuration # $port = 8000; # the port we listen on $htmldir = “./html/“; # the base html directory $cgidir = “./cgi-bin/“; # the base cgi direct

3、ory $server = “Tiny Web server 1.0“; # server info,Tiny: error messages,# # Error messages # # Terse error messages go in the response header %terse_errors = ( “403“, “Forbidden“, “404“, “Not Found“, “501“, “Not Implemented“, ); # Verbose error messages go in the response message body %verbose_error

4、s = ( “403“, “You are not allowed to access this item“, “404“, “Tiny couldnt find the requested item on the server“, “501“, “Tiny does not support the given request type“, );,Tiny: Create a listening socket,# # Create a TCP listening socket file descriptor # # LocalPort: list on port $port # Type :

5、use TCP # Resuse : reuse address right away # Listen : buffer at most 10 requests # $listenfd = IO:Socket:INET-new(LocalPort = $port, Type = SOCK_STREAM, Reuse = 1, Listen = 10) or die “Couldnt listen on port $port: $n“;,Tiny: main loop structure,# # Loop forever waiting for HTTP requests # while(1)

6、 # Wait for a connection request from a client $connfd = $listenfd-accept(); # Determine the domain name and IP address of this client # Parse the request line (after stripping the newline) # Parse the URI# Parse the request headers# OPTIONS method# HEAD method# GET method# misc: POST, PUT, DELETE,

7、and TRACE methods ,Tiny: error procedure,# # error - send an error message back to the client # $_0: the error number # $_1: the method or URI that caused the error # sub error local($errno) = $_0; local($errmsg) = “$errno $terse_errors$errno“; print $connfd $errmsg $errmsg $verbose_errors$errno: $_

8、1 The Tiny Web Server EndOfMessage ,Tiny: get clients name and address,# Determine the domain name and IP address of this client $client_sockaddr = getpeername($connfd); ($client_port, $client_iaddr) = unpack_sockaddr_in($client_sockaddr); $client_port = $client_port; # so -w wont complain $client_n

9、ame = gethostbyaddr($client_iaddr, AF_INET); ($a1, $a2, $a3, $a4) = unpack(C4, $client_iaddr); print “Opened connection with $client_name ($a1.$a2.$a3.$a4)n“;,Tiny: parsing the request line,# Parse the request line (after stripping the newline) chomp($line = ); ($method, $uri, $version) = split(/s+/

10、, $line); print “received $linen“;,Tiny: parsing the URI,# # Parse the URI # # Either the URI refers to a CGI program. if ($uri = m:/cgi-bin/:) $is_static = 0; # extract the program name and its arguments ($filename, $cgiargs) = split(/?/, $uri); if (!defined($cgiargs) $cgiargs = “; # replace /cgi-b

11、in with the default cgi directory $filename = s:/cgi-bin/:$cgidir:o; ,Tiny: Parsing the URI,# . or the URI refers to a file else $is_static = 1; # static content $cgiargs = “; # replace the first / with the default html directory $filename = $uri; $filename = s:/:$htmldir:o; # use index.html for the

12、 default file $filename = s:/$:/index.html:; # debug statements like this will help you a lot print “parsed URI: is_static=$is_static, filename=$filename, cgiargs=$cgiargsn“;,Tiny: parsig the request headers,# # Parse the request headers # $content_length = 0; $content_type = “text/html“; while () #

13、 read request header into $_ # Delete CR and NL chars s/n|r/g; # delete CRLF and CR chars from $_ # Determine the length of the message body # search for “Content-Length:“ at beginning of string $_ # ignore the case if (/Content-Length: (S*)/i) $content_length = $1; ,Tiny: parse the command line (co

14、nt),# determine the type of content (if any) in msg body # search for “Content-Type:“ at beginning of string $_ # ignore the case if (/Content-Type: (S*)/i) $content_type = $1; # If $_ was a blank line, exit the loop if (length = 0) last; ,Tiny: OPTIONS,# # OPTIONS method # if ($method eq “OPTIONS“)

15、 $today = gmtime().“ GMT“; $connfd-print(“$version 200 OKn“); $connfd-print(“Date: $todayn“); $connfd-print(“Server: $servern“); $connfd-print(“Content-length: 0n“); $connfd-print(“Allow: OPTIONS HEAD GETn“); $connfd-print(“n“); ,Tiny: HEAD,# # HEAD method # elsif ($method eq “HEAD“) # were dissallo

16、wing HEAD methods on scripts if (!$is_static) error(403, $filename); else $today = gmtime().“ GMT“; head_method($filename, $uri, $today, $server); ,Tiny: HEAD (cont),# # process the HEAD method on static content # $_0 : the file to be processed # $_1 : the uri # $_2 : todays date # $_3 : server name

17、 # sub head_method local ($filename) = $_0; local ($uri) = $_1; local ($today) = $_2; local ($server) = $_3; local $modified; local $filesize; local $filetype;,Tiny: HEAD (cont),# make sure the requested file exists if (!(-e $filename) error(404, $uri); # make sure the requested is readable elsif (!

18、(-r $filename) error(403, $uri); ,Tiny: HEAD (cont),# serve the response header but not the file else # determine file modifcation date $modified = gmtime(stat($filename)9).“ GMT“; # determine filesize in bytes $filesize = (stat($filename)7; # determin filetype (default is text) if ($filename = /.ht

19、ml$/) $filetype = “text/html“; elsif ($filename = /.gif$/) $filetype = “image/gif“; elsif ($filename = /.jpg$/) $filetype = “image/jpeg“; else $filetype = “text/plain“; ,Tiny: HEAD (cont),# print the response header $connfd-print(“HTTP/1.1 200 OKn“); $connfd-print(“Date: $todayn“); $connfd-print(“Se

20、rver: $servern“); $connfd- print(“Last-modified: $modifiedn“); $connfd- print(“Content-length: $filesizen“); $connfd-print(“Content-type: $filetypen“); print(“n“); # CRLF required by HTTP standard # end of else # end of procedure,Some Tiny issues,How would you serve static and dynamic content with G

21、ET? How would you serve dynamic content with POST? How safe are your CGI scripts? hint: consider the impact of allowing “” in URIs.,Break time!,Fish,Todays lecture,Anatomy of a simple Web server (40 min) Break (10 min) Advanced server features (45 min),Cookies,An HTTP session is a sequence of reques

22、t and response messages between a client and a server. Regular HTTP sessions are stateless Each request/response pair is independent of the others Cookies are a mechanism for creating stateful sessions (RFC 2109) Allows servers and CGI scripts to maintain state information (e.g., which items are in

23、a shopping cart) during a session. Based on HTTP Set-Cookie (server-client) and Cookie (client-server) headers.,Cookies,server,client,request 1,Client initiates request to server.,server,client,response 1 (Set-Cookie),Server includes a Set-Cookie header in the HTTP response that contains info (the c

24、ookie) the identifies the user. The client stores the cookie on disk.,Cookies,server,client,request 2 (Cookie),Next time the client sends a request to the server, it includes the cookie as a Cookie header in the HTTP request message.,server,client,response 2 (Set-Cookie),The server incorporates any

25、relevant new info from request 2 into the Set-Cookie header in response 2.,Cookie example (from RFC 2109),Initially the client has no stored cookies.Client - server POST /acme/login HTTP/1.1 form data user identifies self in form data Server - client HTTP/1.1 200 OK Set-Cookie: Customer=“WILY_COYOTE

26、”; path= “/acme” cookie identifies user client stores cookie for the next request to this server,Cookie example (cont),Client - server POST /acme/pickitem HTTP/1.1 Cookie: Customer=“WILY_COYOTE”; $Path = “/acme” form data User selects an item for a “shopping basket” Server - client HTTP/1.1 200 OK S

27、et-Cookie: Part_Number=“Rocket_Launcher_0001” path=“/acme” Server remembers that shopping basket contains an item,Cookie example (cont),Client - server POST /acme/shipping HTTP/1.1 Cookie: Customer=“WILY_COYOTE”; $Path=“/acme” Part_Number=“Rocket_Launcher_0001”; $Path=“/acme” form data user selects

28、a shipping method from form Server - client HTTP/1.1 200 OK Set-Cookie: Shipping=“FedEx”; path=“/acme”,Cookie example (cont),Client - server POST /acme/process HTTP/1.1 Cookie: Customer=“WILY_COYOTE”; $Path=“/acme”; Part_Number=“Rocket_Launcher_0001”; $Path=“/acme”; Shipping=“FedEx”; $Path=“/acme” f

29、orm data user chooses to process order Server - client HTTP/1.1 200 OK transaction complete,Cookies,Cookies are groups by the URI pathname in the request headers (in this case /acme) The server adds cookies to the client in the response headers. The server an implicitly delete cookies by setting an

30、expiration data in the Set-Cookie header (not shown in previous example),Applications and implications of cookies,Click tracking can be used to correlate a users activity at many different sites. D pays a web site to place an tag on the sites page. Causes an advertising banner and a cookie from D to

31、 be loaded into the client when the sites page is referenced. Firms like Doubleclick maintain a unique id per client machine, but have no way to determine the users name or other info unless the user supplies it.,Applications of cookies,Content customization Cookies can be used to remember user pref

32、erences and customize content to suit those preferences. Firms like Doubleclick can record past browsing patterns and target advertising based on the reference pattern and where they are currently browsing.,Refer links,User looking at page www.cs.cmu.edu/droh/755/foo.html clicks a link to kittyhawk.

33、cmcl.cs.cmu.edu/bar.html Browser sends a referer (sic) header to identify the source page of the request,GET /bar.html HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */* Referer: http:/www.cs.cmu.edu/

34、droh/755/foo.html Accept-Language: en-us Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 98) Host: kittyhawk.cmcl.cs.cmu.edu:8000 Connection: Keep-Alive,Applications of refer links,Allows advertisers to gauge the effectiveness of ads they place on other sites.

35、Allows the kind of 3rd party referral businesses like BeF.,Log files, - - 14/Jul/1999:20:14:38 -0400 “GET /people/faculty/dohallaron HTTP/1.0“ 301 375 “http:/www.ecom.cmu.edu/people/faculty/“ “Mozilla/4.05 en (WinNT; I)“ inet-fw1- - - 15/Jul/1999:02:58:10 -0400 “GET /people/faculty/dohallaron HTTP/1

36、.0“ 301 375 “http:/www.ecom.cmu.edu/people/faculty/“ “Mozilla/4.06 en (WinNT; U)“ - - 15/Jul/1999:16:35:59 -0400 “GET /people/faculty/dohallaron HTTP/1.0“ 301 375 “http:/www.ecom.cmu.edu/people/faculty/“ “Mozilla/4.04 enC-c32f404p (Win95; I)“ - - 16/Jul/1999:16:04:18 -0400 “GET /people/faculty/doh

37、allaron HTTP/1.0“ 301 375 “http:/www.ecom.cmu.edu/people/faculty/“ “Mozilla/4.06 en (Win95; I)“ - - 22/Jul/1999:16:03:51 -0400 “GET /people/faculty/dohallaron/droh.quake.gif HTTP 1.0“ 200 14336 “http:/www.ecom.cmu.edu/people/faculty/dohallaron/“ “Mozilla/4.6C-CCK-MCD en (X,Implications of logs,Cont

38、ain a great deal of personal information about the browsing patterns of people inside and outside a site. Important issue?Who has access to logs? How is the log information being used?,Virtual hosting,Virtual hosting allows one web server to serve requests for multiple domains. Allows ISPs to provid

39、e customers with their own “vanity” sites. Each eCommerce student has their own virtual Web server running at .student.ecom.cmu.edu. e.g., http:/zak.student.ecom.cmu.edu equivalent to http:/euro.ecom.cmu.edu/zack,Virtual hosting: How it works,Configure DNS so that all virtual hosts have the same IP

40、address e.g., each eCommerce student site has the IP address 128.2.218.2 (same as euro.ecom) verify this yourself with nslookup Server maintains a list of (domain name, directory tree) pairs in a hash. Server sets base html and cgi directories according to the target domain name.,Virtual hosting,www

41、,cgi-bin,html,zak,www,cgi-bin,html,elenak,www,cgi-bin,html,mansoo,server,Requests to 128.2.218.2,zak.student.ecom.cmu.edu,elenak.student.ecom.cmu.edu,Server-side includes,Server mechanism that inserts dynamic or static content directly into an HTML document.,some htmlsome more html,some htmlsome more html,

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1