SlideShare una empresa de Scribd logo
1 de 29
WEB APPS WITH PERL
                                 HTTP 101




HENDRIK VAN BELLEGHEM
HENDRIK.VANBELLEGHEM@GMAIL.COM
UNDERSTANDING HTTP




     ONE PAGE, MANY PACKETS
UNDERSTANDING HTTP




      DOCUMENT REQUEST
UNDERSTANDING HTTP




      RESPONSE STATUS
UNDERSTANDING HTTP




       REQUEST DOMAIN
UNDERSTANDING HTTP




       RESPONSE SIZE
UNDERSTANDING HTTP




       RESPONSE TIME
UNDERSTANDING HTTP
UNDERSTANDING HTTP




     BROWSER SENDS
UNDERSTANDING HTTP


    WEBSERVER RESPONDS
DIY

CGI SCRIPT - HELLO WORLD

#!/usr/bin/perl
print quot;Content-type: text/htmlnnquot;;
print quot;Hello Worldquot;;
DIY
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'};
DIY
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'};
CGI.PM

   CGI SCRIPT - HELLO WORLD

#!/usr/bin/perl
use CGI qw(header);
print header;
print “Hello world”;
CGI.PM

   CGI SCRIPT - INTERACTION

#!/usr/bin/perl
use CGI qw(header param);
print header;
my $name = param(‘name’);
print “Hello $name”;
CGI.PM

TRANSPARENT POST & GET

FILE UPLOADS

QUICK COOKIES

HTML GENERATION (NOT MY FAVORITE)

FUNCTION SETS: :CGI = PARAM , HEADER, ...

DROP-IN DEVELOPMENT
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
MOD_PERL 1


16 CYCLES IN MOD_PERL 1

CONTENT HANDLER: PERLHANDLER

LOG HANDLER: PERLLOGHANDLER

AUTHENTICATION HANDLER
MOD_PERL 2


21 CYCLES IN MOD_PERL 2

CONTENT HANDLER: PERLRESPONSEHANDLER

LOG HANDLER: PERLLOGHANDLER

AUTHENTICATION HANDLER
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/
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/
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
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
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
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/
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/
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

Más contenido relacionado

La actualidad más candente

Perl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsPerl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsMatt Follett
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkJeremy Kendall
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkJeremy Kendall
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous Shmuel Fomberg
 
Any event intro
Any event introAny event intro
Any event introqiang
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webWallace Reis
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Arc & Codementor
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Masahiro Nagano
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)xSawyer
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tCosimo Streppone
 
Zend Framework Study@Tokyo vol1
Zend Framework Study@Tokyo vol1Zend Framework Study@Tokyo vol1
Zend Framework Study@Tokyo vol1Shinya Ohyanagi
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHPWim Godden
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutVic Metcalfe
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP GeneratorsMark Baker
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webclkao
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 

La actualidad más candente (20)

PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Perl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsPerl: Hate it for the Right Reasons
Perl: Hate it for the Right Reasons
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
Perl5i
Perl5iPerl5i
Perl5i
 
Any event intro
Any event introAny event intro
Any event intro
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Zend Framework Study@Tokyo vol1
Zend Framework Study@Tokyo vol1Zend Framework Study@Tokyo vol1
Zend Framework Study@Tokyo vol1
 
New in php 7
New in php 7New in php 7
New in php 7
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 

Similar a Web Apps in Perl - HTTP 101

PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Jeff Jones
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHPNat Weerawan
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting languageElmer Concepcion Jr.
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Anatoly Sharifulin
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress WayMatt Wiebe
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareAlona Mekhovova
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.jssouridatta
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and PythonPiXeL16
 

Similar a Web Apps in Perl - HTTP 101 (20)

Lecture8
Lecture8Lecture8
Lecture8
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
Api Design
Api DesignApi Design
Api Design
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
PHP
PHPPHP
PHP
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress Way
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and Python
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
PHP
PHP PHP
PHP
 

Más de hendrikvb

Mojo – Simple REST Server
Mojo – Simple REST ServerMojo – Simple REST Server
Mojo – Simple REST Serverhendrikvb
 
China.z / Trojan.XorDDOS - Analysis of a hack
China.z / Trojan.XorDDOS - Analysis of a hackChina.z / Trojan.XorDDOS - Analysis of a hack
China.z / Trojan.XorDDOS - Analysis of a hackhendrikvb
 
Source Filters in Perl 2010
Source Filters in Perl 2010Source Filters in Perl 2010
Source Filters in Perl 2010hendrikvb
 
Scrabbling Code - Beatnik - YAPC::Eu::2003
Scrabbling Code - Beatnik - YAPC::Eu::2003Scrabbling Code - Beatnik - YAPC::Eu::2003
Scrabbling Code - Beatnik - YAPC::Eu::2003hendrikvb
 
Json In 5 Slices.Key
Json In 5 Slices.KeyJson In 5 Slices.Key
Json In 5 Slices.Keyhendrikvb
 

Más de hendrikvb (6)

Mojo – Simple REST Server
Mojo – Simple REST ServerMojo – Simple REST Server
Mojo – Simple REST Server
 
China.z / Trojan.XorDDOS - Analysis of a hack
China.z / Trojan.XorDDOS - Analysis of a hackChina.z / Trojan.XorDDOS - Analysis of a hack
China.z / Trojan.XorDDOS - Analysis of a hack
 
Source Filters in Perl 2010
Source Filters in Perl 2010Source Filters in Perl 2010
Source Filters in Perl 2010
 
Scrabbling Code - Beatnik - YAPC::Eu::2003
Scrabbling Code - Beatnik - YAPC::Eu::2003Scrabbling Code - Beatnik - YAPC::Eu::2003
Scrabbling Code - Beatnik - YAPC::Eu::2003
 
Json In 5 Slices.Key
Json In 5 Slices.KeyJson In 5 Slices.Key
Json In 5 Slices.Key
 
Cleancode
CleancodeCleancode
Cleancode
 

Último

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Último (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Web Apps in Perl - HTTP 101

  • 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
  • 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

Notas del editor