Web Apps in Perl - HTTP 101

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite & 1 Group

    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 \"Content-type: text/html\\n\\n\"; print \"Hello World\";
    12. DIY
    13. DIY CGI SCRIPT - INTERACTION #!/usr/bin/perl print \"Content-type: text/html\\n\\n\"; @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(\"C\", hex($1))/eg; $value =~ s/\\n/ /g; $request{$name} = $value; } print \"Hello \",$request{'name'};
    14. DIY
    15. DIY CGI SCRIPT - INTERACTION #!/usr/bin/perl MY EYES!!!! print \"Content-type: text/html\\n\\n\"; @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(\"C\", hex($1))/eg; $value =~ s/\\n/ /g; $request{$name} = $value; } THE HORROR!!!! print \"Hello \",$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 \"Content-type: text/plain\\n\\n\"; # MY EYES!! print \"Hello World\\n\"; 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(\"Hello World\\n\"); 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(\"Hello $name\\n\"); 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(\"Hello $name\\n\"); 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 \"Content-type: text/plain\\n\\n\"; # MY EYES!! print \"Hello World\\n\"; 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(\"Hello World\\n\"); 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(\"Hello $name\\n\"); return OK; # read as HTTP status 200 } 1; http://localhost/HelloWorld?name=Bob

    + hendrikvbhendrikvb, 7 months ago

    custom

    1106 views, 1 favs, 1 embeds more stats

    An 15 minute introduction to web applications and w more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1106
      • 1100 on SlideShare
      • 6 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 13
    Most viewed embeds
    • 6 views on http://static.slidesharecdn.com

    more

    All embeds
    • 6 views on http://static.slidesharecdn.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events