Web Apps in Perl - HTTP 101
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Web Apps in Perl - HTTP 101

on

  • 6,875 views

An 15 minute introduction to web applications and writing them in Perl with CGI.pm and mod_perl v1 and v2

An 15 minute introduction to web applications and writing them in Perl with CGI.pm and mod_perl v1 and v2

Statistics

Views

Total Views
6,875
Views on SlideShare
6,853
Embed Views
22

Actions

Likes
0
Downloads
62
Comments
0

3 Embeds 22

http://static.slidesharecdn.com 14
http://www.slideshare.net 7
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />

Web Apps in Perl - HTTP 101 Presentation Transcript

  • 1. WEB APPS WITH PERL HTTP 101 HENDRIK VAN BELLEGHEM HENDRIK.VANBELLEGHEM@GMAIL.COM
  • 2. UNDERSTANDING HTTP ONE PAGE, MANY PACKETS
  • 3. UNDERSTANDING HTTP DOCUMENT REQUEST
  • 4. UNDERSTANDING HTTP RESPONSE STATUS
  • 5. UNDERSTANDING HTTP REQUEST DOMAIN
  • 6. UNDERSTANDING HTTP RESPONSE SIZE
  • 7. UNDERSTANDING HTTP RESPONSE TIME
  • 8. UNDERSTANDING HTTP
  • 9. UNDERSTANDING HTTP BROWSER SENDS
  • 10. UNDERSTANDING HTTP WEBSERVER RESPONDS
  • 11. DIY CGI SCRIPT - HELLO WORLD #!/usr/bin/perl print quot;Content-type: text/htmlnnquot;; print quot;Hello Worldquot;;
  • 12. DIY
  • 13. DIY CGI SCRIPT - INTERACTION #!/usr/bin/perl print quot;Content-type: text/htmlnnquot;; @pairs = split(/&/, $ENV{'QUERY_STRING'}); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(quot;Cquot;, hex($1))/eg; $value =~ s/n/ /g; $request{$name} = $value; } print quot;Hello quot;,$request{'name'};
  • 14. DIY
  • 15. DIY CGI SCRIPT - INTERACTION #!/usr/bin/perl MY EYES!!!! print quot;Content-type: text/htmlnnquot;; @pairs = split(/&/, $ENV{'QUERY_STRING'}); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(quot;Cquot;, hex($1))/eg; $value =~ s/n/ /g; $request{$name} = $value; } THE HORROR!!!! print quot;Hello quot;,$request{'name'};
  • 16. CGI.PM CGI SCRIPT - HELLO WORLD #!/usr/bin/perl use CGI qw(header); print header; print “Hello world”;
  • 17. CGI.PM CGI SCRIPT - INTERACTION #!/usr/bin/perl use CGI qw(header param); print header; my $name = param(‘name’); print “Hello $name”;
  • 18. CGI.PM TRANSPARENT POST & GET FILE UPLOADS QUICK COOKIES HTML GENERATION (NOT MY FAVORITE) FUNCTION SETS: :CGI = PARAM , HEADER, ... DROP-IN DEVELOPMENT
  • 19. MOD_PERL PERL AS AN APACHE MODULE INTERACT WITH EVERY STEP OF APACHE REQUEST CYCLE PERSISTENT COPY OF PERL IN MEMORY NO DROP-IN DEVELOPMENT EXCEPT FOR APACHE::RELOAD
  • 20. MOD_PERL 1 16 CYCLES IN MOD_PERL 1 CONTENT HANDLER: PERLHANDLER LOG HANDLER: PERLLOGHANDLER AUTHENTICATION HANDLER
  • 21. MOD_PERL 2 21 CYCLES IN MOD_PERL 2 CONTENT HANDLER: PERLRESPONSEHANDLER LOG HANDLER: PERLLOGHANDLER AUTHENTICATION HANDLER
  • 22. MOD_PERL 1 CONTENT HANDLER - HELLO WORLD package Apache::HelloWorld; use Apache::Constants qw(:common); # Export OK sub handler # mod_perl uses handler method unless specified otherwise { print quot;Content-type: text/plainnnquot;; # MY EYES!! print quot;Hello Worldnquot;; return OK; # read as HTTP status 200 } 1; PerlModule Apache::HelloWorld <Location /HelloWorld> SetHandler perl-script PerlHandler Apache::HelloWorld </Location> http://localhost/HelloWorld/
  • 23. MOD_PERL 1 CONTENT HANDLER - HELLO WORLD REVISED package Apache::HelloWorld; use Apache::Constants qw(:common); # Export OK sub handler # mod_perl uses handler method unless specified otherwise { my $r = shift; # 1st argument is instance of Apache's Request object $r->send_http_header('text/plain'); # Send HTTP header (similar to CGI's header) $r->print(quot;Hello Worldnquot;); return OK; # read as HTTP status 200 } 1; PerlModule Apache::HelloWorld <Location /HelloWorld> SetHandler perl-script PerlHandler Apache::HelloWorld </Location> http://localhost/HelloWorld/
  • 24. MOD_PERL 1 CONTENT HANDLER - HELLO BOB! package Apache::HelloBob use Apache::Constants qw(:common); # Export OK sub handler # mod_perl uses handler method unless specified otherwise { my $r = shift; # 1st argument is instance of Apache's Request object my %query_string = $r->args; # GET data my %post_data = $r->content; # POST data my $name = $query_string{'name'}; $r->send_http_header('text/plain'); # Send HTTP header (similar to CGI's header) $r->print(quot;Hello $namenquot;); return OK; # read as HTTP status 200 } 1; http://localhost/HelloBob?name=Bob
  • 25. APACHE::REQUEST (A::R) INHERITS FROM APACHE CLASS MIMICS CGI.PM METHODS SUPPORTS FILE UPLOADS SUPPORTS COOKIES - APACHE::COOKIE / APACHE2::COOKIE AVAILABLE FOR MOD_PERL V1 & V2
  • 26. MOD_PERL 1 CONTENT HANDLER - HELLO BOB WITH A::R package Apache::HelloWorld; use Apache::Constants qw(:common); # Export OK use Apache::Request (); # isa Apache sub handler # mod_perl uses handler method unless specified otherwise { my $r = shift; my $apr = Apache::Request->new($r); # Pass Apaches Request object to A::R $apr->send_http_header('text/plain'); my $name = $apr->param(‘name’); # Send HTTP header (similar to CGI's header) $apr->print(quot;Hello $namenquot;); return OK; # read as HTTP status 200 } 1; http://localhost/HelloWorld?name=Bob
  • 27. MOD_PERL 2 CONTENT HANDLER - HELLO WORLD package Apache2::HelloWorld; use Apache2::Const qw(:common); # Export OK sub handler # mod_perl2 uses handler method unless specified otherwise { print quot;Content-type: text/plainnnquot;; # MY EYES!! print quot;Hello Worldnquot;; return OK; # read as HTTP status 200 } 1; PerlModule Apache2::HelloWorld <Location /HelloWorld> SetHandler perl-script PerlResponseHandler Apache2::HelloWorld </Location> http://localhost/HelloWorld/
  • 28. MOD_PERL 2 CONTENT HANDLER - HELLO WORLD REVISED package Apache2::HelloWorld; use Apache2::Const qw(:common); # Export OK sub handler # mod_perl2 uses handler method unless specified otherwise { my $r = shift; # 1st argument is instance of Apache's Request object $r->content_type('text/plain'); # Send HTTP header (similar to CGI's header) $r->print(quot;Hello Worldnquot;); return OK; # read as HTTP status 200 } 1; PerlModule Apache2::HelloWorld <Location /HelloWorld> SetHandler perl-script PerlResponseHandler Apache2::HelloWorld </Location> http://localhost/HelloWorld/
  • 29. MOD_PERL 2 CONTENT HANDLER - HELLO BOB WITH A2::R package Apache2::HelloBob; use Apache2::Const qw(:common); # Export OK use Apache2::Request (); # isa Apache sub handler # mod_perl uses handler method unless specified otherwise { my $r = shift; my $apr = Apache2::Request->new($r); # Pass Apaches Request object to A2::R $apr->send_http_header('text/plain'); my $name = $apr->param(‘name’); # Send HTTP header (similar to CGI's header) $apr->print(quot;Hello $namenquot;); return OK; # read as HTTP status 200 } 1; http://localhost/HelloWorld?name=Bob