vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r16125: LJSUP-5445: add LJ::Request as proxy lay...

Committer: vsukhanov
LJSUP-5445: add LJ::Request as proxy layer between LJ.com's code and Apache v1/v2.
U   trunk/backup/htdocs/create.bml
U   trunk/cgi-bin/Apache/DebateSuicide.pm
U   trunk/cgi-bin/Apache/LiveJournal/Interface/AtomAPI.pm
U   trunk/cgi-bin/Apache/LiveJournal/Interface/ElsewhereInfo.pm
U   trunk/cgi-bin/Apache/LiveJournal/Interface/FotoBilder.pm
U   trunk/cgi-bin/Apache/LiveJournal/Interface/S2.pm
U   trunk/cgi-bin/Apache/LiveJournal/PalImg.pm
U   trunk/cgi-bin/Apache/LiveJournal.pm
U   trunk/cgi-bin/Apache/SendStats.pm
U   trunk/cgi-bin/LJ/AccessLogRecord.pm
U   trunk/cgi-bin/LJ/Config.pm
U   trunk/cgi-bin/LJ/EmbedModule.pm
U   trunk/cgi-bin/LJ/Error.pm
U   trunk/cgi-bin/LJ/Hooks/PingBack.pm
U   trunk/cgi-bin/LJ/NewWorker.pm
U   trunk/cgi-bin/LJ/PageStats.pm
U   trunk/cgi-bin/LJ/PingBack.pm
A   trunk/cgi-bin/LJ/Request/
A   trunk/cgi-bin/LJ/Request.pm
U   trunk/cgi-bin/LJ/S2/EntryPage.pm
U   trunk/cgi-bin/LJ/S2/FriendsPage.pm
U   trunk/cgi-bin/LJ/S2/ReplyPage.pm
U   trunk/cgi-bin/LJ/S2.pm
U   trunk/cgi-bin/LJ/Session.pm
U   trunk/cgi-bin/LJ/URI.pm
U   trunk/cgi-bin/LJ/UniqCookie.pm
U   trunk/cgi-bin/LJ/User.pm
U   trunk/cgi-bin/LJ/Widget/CreateAccount.pm
U   trunk/cgi-bin/LJ/Widget/Login.pm
U   trunk/cgi-bin/LJ/Widget/SettingProdDisplay.pm
U   trunk/cgi-bin/LJ/Widget/VerticalEntries.pm
U   trunk/cgi-bin/bml/scheme/lynx.look
U   trunk/cgi-bin/cleanhtml.pl
U   trunk/cgi-bin/lj-bml-init.pl
U   trunk/cgi-bin/ljfeed.pl
U   trunk/cgi-bin/ljlib.pl
U   trunk/cgi-bin/ljprotocol.pl
U   trunk/cgi-bin/ljviews.pl
U   trunk/cgi-bin/modperl.pl
U   trunk/cgi-bin/modperl_subs.pl
U   trunk/cgi-bin/talklib.pl
U   trunk/cgi-bin/weblib.pl
U   trunk/htdocs/admin/qotd/responses.bml
U   trunk/htdocs/captcha/audio.bml
U   trunk/htdocs/captcha/image.bml
U   trunk/htdocs/customize/advanced/layersource.bml
U   trunk/htdocs/editjournal.bml
U   trunk/htdocs/editpics.bml
U   trunk/htdocs/export_comments.bml
U   trunk/htdocs/export_do.bml
U   trunk/htdocs/extcss/index.bml
U   trunk/htdocs/friends/add.bml
U   trunk/htdocs/imgupload.bml
U   trunk/htdocs/imguploadrte.bml
U   trunk/htdocs/inbox/compose.bml
U   trunk/htdocs/login.bml
U   trunk/htdocs/logout.bml
U   trunk/htdocs/preview/entry.bml
U   trunk/htdocs/support/append_request.bml
U   trunk/htdocs/support/faqbrowse.bml
U   trunk/htdocs/support/help.bml
U   trunk/htdocs/talkpost.bml
U   trunk/htdocs/talkpost_do.bml
U   trunk/htdocs/talkread.bml
U   trunk/htdocs/talkread_s1short.bml
U   trunk/htdocs/tools/embedcontent.bml
U   trunk/htdocs/update.bml
U   trunk/htdocs/userinfo.bml
U   trunk/htdocs/userinfo2.bml
U   trunk/htdocs/userinfo3.bml
U   trunk/htdocs/userinfo_2008.bml
U   trunk/htdocs/view/index.bml
Modified: trunk/backup/htdocs/create.bml
===================================================================
--- trunk/backup/htdocs/create.bml	2010-01-25 07:57:58 UTC (rev 16124)
+++ trunk/backup/htdocs/create.bml	2010-01-25 08:24:36 UTC (rev 16125)
@@ -235,7 +235,7 @@
      if ($LJ::COPPA_CHECK) {
          my $uniq;
          if ($LJ::UNIQ_COOKIES) {
-             $uniq = Apache->request->notes('uniq');
+             $uniq = LJ::Request->notes('uniq');
              if ($uniq) {
                  my $timeof = $dbh->selectrow_array('SELECT timeof FROM underage WHERE uniq = ?', undef, $uniq);
                  $is_underage = 1 if $timeof && $timeof > 0;

Modified: trunk/cgi-bin/Apache/DebateSuicide.pm
===================================================================
--- trunk/cgi-bin/Apache/DebateSuicide.pm	2010-01-25 07:57:58 UTC (rev 16124)
+++ trunk/cgi-bin/Apache/DebateSuicide.pm	2010-01-25 08:24:36 UTC (rev 16125)
@@ -4,7 +4,6 @@
 package Apache::DebateSuicide;
 
 use strict;
-use Apache::Constants qw(:common);
 use Class::Autouse qw(
                       LJ::ModuleCheck
                       );
@@ -16,12 +15,12 @@
 # oh btw, this is totally linux-specific.  gtop didn't work, so so much for portability.
 sub handler
 {
-    my $r = shift;
-    return OK if $r->main;
-    return OK unless $LJ::SUICIDE && LJ::ModuleCheck->have("GTop");
+    #my $r = shift;
+    return LJ::Request::OK if LJ::Request->main;
+    return LJ::Request::OK unless $LJ::SUICIDE && LJ::ModuleCheck->have("GTop");
 
     my $meminfo;
-    return OK unless open (MI, "/proc/meminfo");
+    return LJ::Request::OK unless open (MI, "/proc/meminfo");
     $meminfo = join('', <MI>);
     close MI;
 
@@ -31,7 +30,7 @@
     }
 
     my $memfree = $meminfo{'MemFree'} + $meminfo{'Cached'};
-    return OK unless $memfree;
+    return LJ::Request::OK unless $memfree;
 
     my $goodfree = $LJ::SUICIDE_UNDER{$LJ::SERVER_NAME} || $LJ::SUICIDE_UNDER ||   150_000;
     my $is_under = $memfree < $goodfree;
@@ -51,7 +50,7 @@
 
         $is_over = $proc_size_k > $maxproc;
     }
-    return OK unless $is_over || $is_under;
+    return LJ::Request::OK unless $is_over || $is_under;
 
     # we'll proceed to die if we're one of the largest processes
     # on this machine
@@ -77,17 +76,17 @@
     if (grep { $$ == $_ } @pids[0,1]) {
         my $my_use_k = $stats{$$}[0] >> 10;
         if ($LJ::DEBUG{'suicide'}) {
-            $r->log_error("Suicide [$$]: system memory free = ${memfree}k; " .
+            LJ::Request->log_error("Suicide [$$]: system memory free = ${memfree}k; " .
                           "i'm big, using ${my_use_k}k");
         }
 
         # we should have logged by here, but be paranoid in any case
-        Apache::LiveJournal::db_logger($r) unless $r->pnotes('did_lj_logging');
+        Apache::LiveJournal::db_logger() unless LJ::Request->pnotes('did_lj_logging');
 
         # This is supposed to set MaxChildRequests to 1, then clear the
         # KeepAlive flag so that Apache will terminate after this request,
         # but it doesn't work.  We'll call it here just in case.
-        $r->child_terminate;
+        LJ::Request->child_terminate;
 
         # We should call Apache::exit(Apache::Constants::DONE) here because
         # it makes sure that the child shuts down cleanly after fulfilling
@@ -101,7 +100,7 @@
         CORE::exit(0);
     }
 
-    return OK;
+    return LJ::Request::OK;
 }
 
 sub pid_info {

Modified: trunk/cgi-bin/Apache/LiveJournal/Interface/AtomAPI.pm
===================================================================
--- trunk/cgi-bin/Apache/LiveJournal/Interface/AtomAPI.pm	2010-01-25 07:57:58 UTC (rev 16124)
+++ trunk/cgi-bin/Apache/LiveJournal/Interface/AtomAPI.pm	2010-01-25 08:24:36 UTC (rev 16125)
@@ -3,7 +3,6 @@
 package Apache::LiveJournal::Interface::AtomAPI;
 
 use strict;
-use Apache::Constants qw(:common);
 use Digest::SHA1;
 use MIME::Base64;
 use lib "$ENV{LJHOME}/cgi-bin";
@@ -15,8 +14,7 @@
 sub load { 1 }
 
 # check allowed Atom upload filetypes
-sub check_mime
-{
+sub check_mime {
     my $mime = shift;
     return unless $mime;
 
@@ -33,7 +31,7 @@
 }
 
 sub respond {
-    my ($r, $status, $body, $type) = @_;
+    my ($status, $body, $type) = @_;
 
     my %msgs = (
         200 => 'OK',
@@ -67,16 +65,16 @@
     }
 
     $type = $mime{$type} || 'text/html';
-    $r->status_line("$status $msgs{$status}");
-    $r->content_type($type);
-    $r->send_http_header();
-    $r->print($out);
-    return OK;
+    LJ::Request->status_line("$status $msgs{$status}");
+    LJ::Request->content_type($type);
+    LJ::Request->send_http_header();
+    LJ::Request->print($out);
+    return LJ::Request::OK;
 };
 
 sub handle_upload
 {
-    my ($r, $remote, $u, $opts, $entry) = @_;
+    my ($remote, $u, $opts, $entry) = @_;
 
     # entry could already be populated from a standalone
     # service.post posting.
@@ -85,24 +83,24 @@
         my $buff;
 
         # Check length
-        my $len = $r->header_in("Content-length");
-        return respond($r, 400, "Content is too long")
+        my $len = LJ::Request->header_in("Content-length");
+        return respond(400, "Content is too long")
             if $len > $LJ::MAX_ATOM_UPLOAD;
 
-        $r->read($buff, $len);
+        LJ::Request->read($buff, $len);
 
         eval { $entry = XML::Atom::Entry->new( \$buff ); };
-        return respond($r, 400, "Could not parse the entry due to invalid markup.<br /><pre>$@</pre>")
+        return respond(400, "Could not parse the entry due to invalid markup.<br /><pre>$@</pre>")
             if $@;
     }
 
     my $mime = $entry->content()->type();
     my $mime_area = check_mime( $mime );
-    return respond($r, 400, "Unsupported MIME type: $mime") unless $mime_area;
+    return respond(400, "Unsupported MIME type: $mime") unless $mime_area;
 
     if ($mime_area eq 'image') {
 
-        return respond($r, 400, "Unable to upload media. Your account doesn't have the required access.")
+        return respond(400, "Unable to upload media. Your account doesn't have the required access.")
             unless LJ::get_cap($u, 'fb_can_upload') && $LJ::FB_SITEROOT;
 
         my $err;
@@ -124,12 +122,12 @@
             }
         );
 
-        return respond($r, 500, "There was an error uploading the media: $err")
+        return respond(500, "There was an error uploading the media: $err")
             if $err || ! $fb;
 
         if (ref $fb && $fb->{Error}->{code}) {
             my $errstr = $fb->{Error}->{content};
-            return respond($r, 500, "There was an error uploading the media: $errstr");
+            return respond(500, "There was an error uploading the media: $errstr");
         }
 
         my $atom_reply = XML::Atom::Entry->new();
@@ -151,30 +149,30 @@
         $link->href( $fb->{URL} );
         $atom_reply->add_link($link);
 
-        $r->header_out("Location", $fb->{URL});
-        return respond($r, 201, \$atom_reply->as_xml(), 'atom');
+        LJ::Request->header_out("Location", $fb->{URL});
+        return respond(201, \$atom_reply->as_xml(), 'atom');
     }
 }
 
 sub handle_post {
-    my ($r, $remote, $u, $opts) = @_;
+    my ($remote, $u, $opts) = @_;
     my ($buff, $entry);
 
     # Check length
-    my $len = $r->header_in("Content-length");
-    return respond($r, 400, "Content is too long")
+    my $len = LJ::Request->header_in("Content-length");
+    return respond(400, "Content is too long")
         if $len > $LJ::MAX_ATOM_UPLOAD;
 
     # read the content
-    $r->read($buff, $len);
+    LJ::Request->read($buff, $len);
 
     # try parsing it
     eval { $entry = XML::Atom::Entry->new( \$buff ); };
-    return respond($r, 400, "Could not parse the entry due to invalid markup.<br /><pre>$@</pre>")
+    return respond(400, "Could not parse the entry due to invalid markup.<br /><pre>$@</pre>")
         if $@;
 
     # on post, the entry must NOT include an id
-    return respond($r, 400, "Must not include an <b>&lt;id&gt;</b> field in a new entry.")
+    return respond(400, "Must not include an <b>&lt;id&gt;</b> field in a new entry.")
         if $entry->id;
 
     # detect 'standalone' media posts
@@ -290,7 +288,7 @@
 
     if ($err) {
         my $errstr = LJ::Protocol::error_message($err);
-        return respond($r, 500, "Unable to post new entry. Protocol error: <b>$errstr</b>.");
+        return respond(500, "Unable to post new entry. Protocol error: <b>$errstr</b>.");
     }
 
     my $atom_reply = XML::Atom::Entry->new();
@@ -341,12 +339,12 @@
     $link->title( $entry->title() );
     $atom_reply->add_link($link);
 
-    $r->header_out("Location", $edit_url);
-    return respond($r, 201, \$atom_reply->as_xml(), 'atom');
+    LJ::Request->header_out("Location", $edit_url);
+    return respond(201, \$atom_reply->as_xml(), 'atom');
 }
 
 sub handle_edit {
-    my ($r, $remote, $u, $opts) = @_;
+    my ($remote, $u, $opts) = @_;
 
     my $method = $opts->{'method'};
 
@@ -367,7 +365,7 @@
 
     if ($err) {
         my $errstr = LJ::Protocol::error_message($err);
-        return respond($r, 404, "Unable to retrieve the item requested for editing. Protocol error: <b>$errstr</b>.");
+        return respond(404, "Unable to retrieve the item requested for editing. Protocol error: <b>$errstr</b>.");
     }
     $olditem = $olditem->{'events'}->[0];
 
@@ -378,7 +376,7 @@
 
         # get the log2 row (need logtime for createtime)
         my $row = LJ::get_log2_row($u, $jitemid) ||
-            return respond($r, 404, "Could not load the original entry.");
+            return respond(404, "Could not load the original entry.");
 
         # we need to put into $item: itemid, ditemid, subject, event,
         # createtime, eventtime, modtime
@@ -409,23 +407,23 @@
             [$item]
         );
 
-        return respond($r, 200, \$ret, 'xml');
+        return respond(200, \$ret, 'xml');
     }
 
     if ($method eq "PUT") {
         # Check length
-        my $len = $r->header_in("Content-length");
-        return respond($r, 400, "Content is too long")
+        my $len = LJ::Request->header_in("Content-length");
+        return respond(400, "Content is too long")
             if $len > $LJ::MAX_ATOM_UPLOAD;
 
         # read the content
         my $buff;
-        $r->read($buff, $len);
+        LJ::Request->read($buff, $len);
 
         # try parsing it
         my $entry;
         eval { $entry = XML::Atom::Entry->new( \$buff ); };
-        return respond($r, 400, "Could not parse the entry due to invalid markup.<br /><pre>$@</pre>")
+        return respond(400, "Could not parse the entry due to invalid markup.<br /><pre>$@</pre>")
             if $@;
 
         # remove the SvUTF8 flag. See same code in synsuck.pl for
@@ -438,7 +436,7 @@
         # on GET
         unless ($entry->id() =~ m#atom1:$u->{'user'}:(\d+)$# &&
                 $1 == $olditem->{'itemid'}*256 + $olditem->{'anum'}) {
-            return respond($r, 400, "Incorrect <b>&lt;id&gt;</b> field in this request.");
+            return respond(400, "Incorrect <b>&lt;id&gt;</b> field in this request.");
         }
 
         # build an edit event request. Preserve fields that aren't being
@@ -464,10 +462,10 @@
 
         if ($err) {
             my $errstr = LJ::Protocol::error_message($err);
-            return respond($r, 500, "Unable to update entry. Protocol error: <b>$errstr</b>.");
+            return respond(500, "Unable to update entry. Protocol error: <b>$errstr</b>.");
         }
 
-        return respond($r, 200, "The entry was successfully updated.");
+        return respond(200, "The entry was successfully updated.");
     }
 
     if ($method eq "DELETE") {
@@ -490,10 +488,10 @@
 
         if ($err) {
             my $errstr = LJ::Protocol::error_message($err);
-            return respond($r, 500, "Unable to delete entry. Protocol error: <b>$errstr</b>.");
+            return respond(500, "Unable to delete entry. Protocol error: <b>$errstr</b>.");
         }
 
-        return respond($r, 200, "Entry successfully deleted.");
+        return respond(200, "Entry successfully deleted.");
     }
 
 }
@@ -501,7 +499,7 @@
 # fetch lj tags, display as categories
 sub handle_categories
 {
-    my ($r, $remote, $u, $opts) = @_;
+    my ($remote, $u, $opts) = @_;
     my $ret = '<?xml version="1.0"?>';
     $ret .= '<categories xmlns="http://sixapart.com/atom/category#">';
 
@@ -511,11 +509,11 @@
     }
     $ret .= '</categories>';
 
-    return respond($r, 200, \$ret, 'xml');
+    return respond(200, \$ret, 'xml');
 }
 
 sub handle_feed {
-    my ($r, $remote, $u, $opts) = @_;
+    my ($remote, $u, $opts) = @_;
 
     # simulate a call to the S1 data view creator, with appropriate
     # options
@@ -523,7 +521,7 @@
     my %op = ('pathextra' => "/atom",
               'apilinks'  => 1,
               );
-    my $ret = LJ::Feed::make_feed($r, $u, $remote, \%op);
+    my $ret = LJ::Feed::make_feed($u, $remote, \%op);
 
     unless (defined $ret) {
         if ($op{'redir'}) {
@@ -531,19 +529,19 @@
             # the redir URL is wrong because ljfeed.pl is too
             # dataview-specific. Since this is an admin interface, we can
             # just fail.
-            return respond ($r, 404, "The account <b>$u->{'user'} </b> is of a wrong type and does not allow AtomAPI administration.");
+            return respond(404, "The account <b>$u->{'user'} </b> is of a wrong type and does not allow AtomAPI administration.");
         }
         if ($op{'handler_return'}) {
             # this could be a conditional GET shortcut, honor it
-            $r->status($op{'handler_return'});
-            return OK;
+            LJ::Request->status($op{'handler_return'});
+            return LJ::Request::OK;
         }
         # should never get here
-        return respond ($r, 404, "Unknown error.");
+        return respond(404, "Unknown error.");
     }
 
     # everything's fine, return the XML body with the correct content type
-    return respond($r, 200, \$ret, 'xml');
+    return respond(200, \$ret, 'xml');
 
 }
 
@@ -551,7 +549,6 @@
 # authentication, calls the appropriate method handler, and
 # prints the response.
 sub handle {
-    my $r = shift;
 
     my $have_xmlatom = eval {
         require XML::Atom;
@@ -561,12 +558,12 @@
         XML::Atom->VERSION < 0.09 ? 0 : 1
     };
 
-    return respond($r, 404, "This server does not support the Atom API.")
+    return respond(404, "This server does not support the Atom API.")
         unless $have_xmlatom;
 
     # break the uri down: /interface/atom/<verb>[/<number>]
     # or old format:      /interface/atomapi/<username>/<verb>[/<number>]
-    my $uri = $r->uri;
+    my $uri = LJ::Request->uri;
 
     # convert old format to new format:
     my $username;   # old
@@ -574,7 +571,7 @@
         $username = $1;
     }
 
-    $uri =~ s!^/interface/atom/?!! or return respond($r, 404, "Bogus URL");
+    $uri =~ s!^/interface/atom/?!! or return respond(404, "Bogus URL");
     my ($action, $param) = split(m!/!, $uri);
 
     my $valid_actions = qr{feed|edit|post|upload|categories};
@@ -583,18 +580,18 @@
     #
     # if wsse information is supplied, use it.
     # if not, fall back to digest.
-    my $wsse = $r->header_in('X-WSSE');
+    my $wsse = LJ::Request->header_in('X-WSSE');
     my $nonce_dup;
-    my $u = $wsse ? auth_wsse($wsse, \$nonce_dup) : LJ::auth_digest($r);
-    return respond( $r, 401, "Authentication failed for this AtomAPI request.")
+    my $u = $wsse ? auth_wsse($wsse, \$nonce_dup) : LJ::auth_digest();
+    return respond(401, "Authentication failed for this AtomAPI request.")
         unless $u;
 
-    return respond( $r, 401, "Authentication failed for this AtomAPI request.")
+    return respond(401, "Authentication failed for this AtomAPI request.")
         if $nonce_dup && $action && $action ne 'post';
 
     # service autodiscovery
     # TODO: Add communities?
-    my $method = $r->method;
+    my $method = LJ::Request->method;
     if ( $method eq 'GET' && ! $action ) {
         LJ::load_user_props( $u, 'journaltitle' );
         my $title = $u->{journaltitle} || $u->{user};
@@ -623,11 +620,11 @@
         $link->href( LJ::journal_base($u) );
         $feed->add_link($link);
 
-        return respond($r, 200, \$feed->as_xml(), 'atom');
+        return respond(200, \$feed->as_xml(), 'atom');
     }
 
     $action =~ /^$valid_actions$/
-      or return respond($r, 400, "Unknown URI scheme: /interface/atom/<b>" . LJ::ehtml($action) . "</b>");
+      or return respond(400, "Unknown URI scheme: /interface/atom/<b>" . LJ::ehtml($action) . "</b>");
 
     unless (($action eq 'feed' and $method eq 'GET')  or
             ($action eq 'categories' and $method eq 'GET') or
@@ -635,19 +632,19 @@
             ($action eq 'upload' and $method eq 'POST') or
             ($action eq 'edit' and
              {'GET'=>1,'PUT'=>1,'DELETE'=>1}->{$method})) {
-        return respond($r, 400, "URI scheme /interface/atom/<b>" . LJ::ehtml($action) . "</b> is incompatible with request method <b>$method</b>.");
+        return respond(400, "URI scheme /interface/atom/<b>" . LJ::ehtml($action) . "</b> is incompatible with request method <b>$method</b>.");
     }
 
     if (($action ne 'edit' && $param) or
         ($action eq 'edit' && $param !~ m#^\d+$#)) {
-        return respond($r, 400, "Either the URI lacks a required parameter, or its format is improper.");
+        return respond(400, "Either the URI lacks a required parameter, or its format is improper.");
     }
 
     # we've authenticated successfully and remote is set. But can remote
     # manage the requested account?
     my $remote = LJ::get_remote();
     unless (LJ::can_manage($remote, $u)) {
-        return respond($r, 403, "User <b>$remote->{'user'}</b> has no administrative access to account <b>$u->{user}</b>.");
+        return respond(403, "User <b>$remote->{'user'}</b> has no administrative access to account <b>$u->{user}</b>.");
     }
 
     # handle the requested action
@@ -663,9 +660,9 @@
         'edit'       => \&handle_edit,
         'upload'     => \&handle_upload,
         'categories' => \&handle_categories,
-    }->{$action}->( $r, $remote, $u, $opts );
+    }->{$action}->($remote, $u, $opts);
 
-    return OK;
+    return LJ::Request::OK;
 }
 
 # Authenticate via the WSSE header.

Modified: trunk/cgi-bin/Apache/LiveJournal/Interface/ElsewhereInfo.pm
===================================================================
--- trunk/cgi-bin/Apache/LiveJournal/Interface/ElsewhereInfo.pm	2010-01-25 07:57:58 UTC (rev 16124)
+++ trunk/cgi-bin/Apache/LiveJournal/Interface/ElsewhereInfo.pm	2010-01-25 08:24:36 UTC (rev 16125)
@@ -13,7 +13,6 @@
 sub load { 1 }
 
 sub should_handle {
-    my $r = shift;
 
     # FIXME: trust specific consumers of this data?
     return $LJ::IS_DEV_SERVER ? 1 : 0;
@@ -24,27 +23,27 @@
 # prints the response.
 sub handle {
     shift if $_[0] eq __PACKAGE__;
-    my $r = shift;
+    #my $r = shift;
 
-    my %args = $r->args;
+    my %args = LJ::Request->args;
 
     # should we handle this request due according to access rules?
-    unless (should_handle($r)) {
-        return respond($r, 403, "Forbidden");
+    unless (should_handle()) {
+        return respond(403, "Forbidden");
     }
 
     # find what node_u we're dealing with
     my $u;
     if (my $id = $args{id}) {
         $u = LJ::load_userid($id);
-        return respond($r, 404, "Invalid id: $id")
+        return respond(404, "Invalid id: $id")
             unless $u;
     } elsif (my $node = $args{ident}) {
         $u = LJ::load_user($node);
-        return respond($r, 404, "Invalid ident: $node")
+        return respond(404, "Invalid ident: $node")
             unless $u;
     } else {
-        return respond($r, 400, "Must specify 'id' or 'ident'");
+        return respond(400, "Must specify 'id' or 'ident'");
     }
 
     # find what node type we're dealing with
@@ -58,7 +57,7 @@
         $node_type = 'openid';
         $node_ident = $u->url; # should be identity type O
     } else {
-        return respond($r, 403, "Node is neither person, group, nor openid: " . $u->user . " (" . $u->id . ")");
+        return respond(403, "Node is neither person, group, nor openid: " . $u->user . " (" . $u->id . ")");
     }
 
     # response hash to pass to JSON
@@ -86,13 +85,13 @@
         $resp{edges_out} = [ map { $_ } $u->friend_uids   ];
     }
 
-    respond($r, 200, JSON::objToJson(\%resp));
+    respond(200, JSON::objToJson(\%resp));
 
-    return OK;
+    return LJ::Request::OK;
 }
 
 sub respond {
-    my ($r, $status, $body) = @_;
+    my ($status, $body) = @_;
 
     my %msgs = (
                 200 => 'OK',
@@ -102,12 +101,12 @@
                 500 => 'Server Error',
                 );
 
-    $r->status_line(join(" ", grep { length } $status, $msgs{$status}));
-    $r->content_type('text/html');#'application/json');
-    $r->send_http_header();
-    $r->print($body);
+    LJ::Request->status_line(join(" ", grep { length } $status, $msgs{$status}));
+    LJ::Request->content_type('text/html');#'application/json');
+    LJ::Request->send_http_header();
+    LJ::Request->print($body);
 
-    return OK;
+    return LJ::Request::OK;
 };
 
 1;

Modified: trunk/cgi-bin/Apache/LiveJournal/Interface/FotoBilder.pm
===================================================================
--- trunk/cgi-bin/Apache/LiveJournal/Interface/FotoBilder.pm	2010-01-25 07:57:58 UTC (rev 16124)
+++ trunk/cgi-bin/Apache/LiveJournal/Interface/FotoBilder.pm	2010-01-25 08:24:36 UTC (rev 16125)
@@ -4,8 +4,6 @@
 package Apache::LiveJournal::Interface::FotoBilder;
 
 use strict;
-use Apache::Constants qw(:common REDIRECT HTTP_NOT_MODIFIED
-                         HTTP_MOVED_PERMANENTLY BAD_REQUEST);
 
 sub run_method
 {
@@ -28,25 +26,24 @@
 
 sub handler
 {
-    my $r = shift;
-    my $uri = $r->uri;
-    return 404 unless $uri =~ m#^/interface/fotobilder(?:/(\w+))?$#;
+    my $uri = LJ::Request->uri;
+    return LJ::Request::NOT_FOUND unless $uri =~ m#^/interface/fotobilder(?:/(\w+))?$#;
     my $cmd = $1;
 
-    return BAD_REQUEST unless $r->method eq "POST";
+    return LJ::Request::BAD_REQUEST unless LJ::Request->method eq "POST";
 
-    $r->content_type("text/plain");
-    $r->send_http_header();
+    LJ::Request->content_type("text/plain");
+    LJ::Request->send_http_header();
 
-    my %POST = $r->content;
+    my %POST = LJ::Request->post_params;
     my $res = run_method($cmd, \%POST)
-        or return BAD_REQUEST;
+        or return LJ::Request::BAD_REQUEST;
 
     $res->{"fotobilder-interface-version"} = 1;
 
-    $r->print(join("", map { "$_: $res->{$_}\n" } keys %$res));
+    LJ::Request->print(join("", map { "$_: $res->{$_}\n" } keys %$res));
 
-    return OK;
+    return LJ::Request::OK;
 }
 
 # Is there a current LJ session?

Modified: trunk/cgi-bin/Apache/LiveJournal/Interface/S2.pm
===================================================================
--- trunk/cgi-bin/Apache/LiveJournal/Interface/S2.pm	2010-01-25 07:57:58 UTC (rev 16124)
+++ trunk/cgi-bin/Apache/LiveJournal/Interface/S2.pm	2010-01-25 08:24:36 UTC (rev 16125)
@@ -5,49 +5,47 @@
 
 use strict;
 use MIME::Base64 ();
-use Apache::Constants;
 
 sub load { 1 }
 
 sub handler {
-    my $r = shift;
 
-    my $meth = $r->method();
-    my %GET = $r->args();
-    my $uri = $r->uri();
+    my $meth = LJ::Request->method();
+    my %GET = LJ::Request->args();
+    my $uri = LJ::Request->uri();
     my $id;
     if ($uri =~ m!^/interface/s2/(\d+)$!) {
         $id = $1 + 0;
     } else {
-        return NOT_FOUND;
+        return LJ::Request::NOT_FOUND;
     }
 
     my $lay = LJ::S2::load_layer($id);
-    return error($r, 404, 'Layer not found', "There is no layer with id $id at this site")
+    return error(404, 'Layer not found', "There is no layer with id $id at this site")
         unless $lay;
 
-    LJ::auth_digest($r);
+    LJ::auth_digest(LJ::Request->r);
     my $u = LJ::get_remote();
     unless ($u) {
         # Tell the client how it can authenticate
         # use digest authorization.
 
-        $r->send_http_header("text/plain; charset=utf-8");
-        $r->print("Unauthorized\nYou must send your $LJ::SITENAME username and password or a valid session cookie\n");
+        LJ::Request->send_http_header("text/plain; charset=utf-8");
+        LJ::Request->print("Unauthorized\nYou must send your $LJ::SITENAME username and password or a valid session cookie\n");
 
-        return OK;
+        return LJ::Request::OK;
     }
 
     my $dbr = LJ::get_db_reader();
 
     my $lu = LJ::load_userid($lay->{'userid'});
 
-    return error($r, 500, "Error", "Unable to find layer owner.")
+    return error(500, "Error", "Unable to find layer owner.")
         unless $lu;
 
     if ($meth eq 'GET') {
 
-        return error($r, 403, "Forbidden", "You are not authorized to retrieve this layer")
+        return error(403, "Forbidden", "You are not authorized to retrieve this layer")
             unless $lu->{'user'} eq 'system' || LJ::can_manage($u, $lu);
 
         my $layerinfo = {};
@@ -56,71 +54,71 @@
             $layerinfo->{$id}->{'source_viewable'} : 1;
 
         # Disallow retrieval of protected system layers
-        return error($r, 403, "Forbidden", "The requested layer is restricted")
+        return error(403, "Forbidden", "The requested layer is restricted")
             if $lu->{'user'} eq 'system' && ! $srcview;
 
         my $s2code = LJ::S2::load_layer_source($id);
 
-        $r->send_http_header("application/x-danga-s2-layer");
-        $r->print($s2code);
+        LJ::Request->send_http_header("application/x-danga-s2-layer");
+        LJ::Request->print($s2code);
 
     }
     elsif ($meth eq 'PUT') {
 
-        return error($r, 403, "Forbidden", "You are not authorized to edit this layer")
+        return error(403, "Forbidden", "You are not authorized to edit this layer")
             unless LJ::can_manage($u, $lu);
 
-        return error($r, 403, "Forbidden", "Your account type is not allowed to edit layers")
+        return error(403, "Forbidden", "Your account type is not allowed to edit layers")
             unless LJ::get_cap($u, "s2styles");
 
         # Read in the entity body to get the source
-        my $len = $r->header_in("Content-length")+0;
+        my $len = LJ::Request->header_in("Content-length")+0;
 
-        return error($r, 400, "Bad Request", "Supply S2 layer code in the request entity body and set Content-length")
+        return error(400, "Bad Request", "Supply S2 layer code in the request entity body and set Content-length")
             unless $len;
 
-        return error($r, 415, "Bad Media Type", "Request body must be of type application/x-danga-s2-layer")
-            unless lc($r->header_in("Content-type")) eq 'application/x-danga-s2-layer';
+        return error(415, "Bad Media Type", "Request body must be of type application/x-danga-s2-layer")
+            unless lc(LJ::Request->header_in("Content-type")) eq 'application/x-danga-s2-layer';
 
         my $s2code;
-        $r->read($s2code, $len);
+        LJ::Request->read($s2code, $len);
 
         my $error = "";
         LJ::S2::layer_compile($lay, \$error, { 's2ref' => \$s2code });
 
         if ($error) {
-            error($r, 500, "Layer Compile Error", "An error was encountered while compiling the layer.");
+            error(500, "Layer Compile Error", "An error was encountered while compiling the layer.");
 
             ## Strip any absolute paths
             $error =~ s/LJ::.+//s;
             $error =~ s!, .+?(src/s2|cgi-bin)/!, !g;
 
             print $error;
-            return OK;
+            return LJ::Request::OK;
         }
         else {
-            $r->status_line("201 Compiled and Saved");
-            $r->header_out("Location" => "$LJ::SITEROOT/interface/s2/$id");
-            $r->send_http_header("text/plain; charset=utf-8");
-            $r->print("Compiled and Saved\nThe layer was uploaded successfully.\n");
+            LJ::Request->status_line("201 Compiled and Saved");
+            LJ::Request->header_out("Location" => "$LJ::SITEROOT/interface/s2/$id");
+            LJ::Request->send_http_header("text/plain; charset=utf-8");
+            LJ::Request->print("Compiled and Saved\nThe layer was uploaded successfully.\n");
         }
     }
     else {
         #  Return 'method not allowed' so that we can add methods in future
         # and clients will get a sensible error from old servers.
-        return error($r, 405, 'Method Not Allowed', 'Only GET and PUT are supported for this resource');
+        return error(405, 'Method Not Allowed', 'Only GET and PUT are supported for this resource');
     }
 }
 
 sub error {
-    my ($r, $code, $string, $long) = @_;
+    my ($code, $string, $long) = @_;
 
-    $r->status_line("$code $string");
-    $r->send_http_header("text/plain; charset=utf-8");
-    $r->print("$string\n$long\n");
+    LJ::Request->status_line("$code $string");
+    LJ::Request->send_http_header("text/plain; charset=utf-8");
+    LJ::Request->print("$string\n$long\n");
 
     # Tell Apache OK so it won't try to handle the error
-    return OK;
+    return LJ::Request::OK;
 }
 
 1;

Modified: trunk/cgi-bin/Apache/LiveJournal/PalImg.pm
===================================================================
--- trunk/cgi-bin/Apache/LiveJournal/PalImg.pm	2010-01-25 07:57:58 UTC (rev 16124)
+++ trunk/cgi-bin/Apache/LiveJournal/PalImg.pm	2010-01-25 08:24:36 UTC (rev 16125)
@@ -4,7 +4,7 @@
 package Apache::LiveJournal::PalImg;
 
 use strict;
-use Apache::Constants qw(:common REDIRECT HTTP_NOT_MODIFIED);
+#use Apache::Constants qw(:common REDIRECT HTTP_NOT_MODIFIED);
 use PaletteModify;
 
 # for callers to 'ping' as a class method for Class::Autouse to lazily load
@@ -16,14 +16,14 @@
 
 sub handler
 {
-    my $r = shift;
-    my $uri = $r->uri;
+    #my $r = shift;
+    my $uri = LJ::Request->uri;
     my ($base, $ext, $extra) = $uri =~ m!^/palimg/(.+)\.(\w+)(.*)$!;
-    $r->notes("codepath" => "img.palimg");
-    return 404 unless $base && $base !~ m!\.\.!;
+    LJ::Request->notes("codepath" => "img.palimg");
+    return LJ::Request::NOT_FOUND unless $base && $base !~ m!\.\.!;
 
     my $disk_file = "$LJ::HOME/htdocs/palimg/$base.$ext";
-    return 404 unless -e $disk_file;
+    return LJ::Request::NOT_FOUND unless -e $disk_file;
 
     my @st = stat(_);
     my $size = $st[7];
@@ -40,11 +40,11 @@
         if ($extra =~ m!^/p(.+)$!) {
             $palspec = $1;
         } else {
-            return 404;
+            return LJ::Request::NOT_FOUND;
         }
     }
 
-    return send_file($r, $disk_file, {
+    return send_file($disk_file, {
         'mime' => $mime,
         'etag' => $etag,
         'palspec' => $palspec,
@@ -61,7 +61,7 @@
 
 sub send_file
 {
-    my ($r, $disk_file, $opts) = @_;
+    my ($disk_file, $opts) = @_;
 
     my $etag = $opts->{'etag'};
 
@@ -73,7 +73,7 @@
             # gradient from index $1, color $2, to index $3, color $4
             my $from = hex($1);
             my $to = hex($3);
-            return 404 if $from == $to;
+            return LJ::Request::NOT_FOUND if $from == $to;
             my $fcolor = parse_hex_color($2);
             my $tcolor = parse_hex_color($4);
             if ($to < $from) {
@@ -94,10 +94,10 @@
             $pal_colors{'tint'} = parse_hex_color($t);
             $pal_colors{'tint_dark'} = $td ? parse_hex_color($td) : [0,0,0];
         } elsif (length($pals) > 42 || $pals =~ /[^0-9a-f]/) {
-            return 404;
+            return LJ::Request::NOT_FOUND;
         } else {
             my $len = length($pals);
-            return 404 if $len % 7;  # must be multiple of 7 chars
+            return LJ::Request::NOT_FOUND if $len % 7;  # must be multiple of 7 chars
             for (my $i = 0; $i < $len/7; $i++) {
                 my $palindex = hex(substr($pals, $i*7, 1));
                 $pal_colors{$palindex} = [
@@ -112,25 +112,48 @@
     }
 
     $etag = '"' . $etag . '"';
-    my $ifnonematch = $r->header_in("If-None-Match");
-    return HTTP_NOT_MODIFIED if
+    my $ifnonematch = LJ::Request->header_in("If-None-Match");
+    return LJ::Request::HTTP_NOT_MODIFIED if
         defined $ifnonematch && $etag eq $ifnonematch;
 
     # send the file
-    $r->content_type($opts->{'mime'});
-    $r->header_out("Content-length", $opts->{'size'});
-    $r->header_out("ETag", $etag);
+    LJ::Request->content_type($opts->{'mime'});
+    LJ::Request->header_out("Content-length", $opts->{'size'});
+    LJ::Request->header_out("ETag", $etag);
     if ($opts->{'modtime'}) {
-        $r->update_mtime($opts->{'modtime'});
-        $r->set_last_modified();
+        LJ::Request->update_mtime($opts->{'modtime'});
+        LJ::Request->set_last_modified();
     }
-    $r->send_http_header();
+    LJ::Request->send_http_header();
 
     # HEAD request?
-    return OK if $r->method eq "HEAD";
+    return LJ::Request::OK if LJ::Request->method eq "HEAD";
 
+    # this is slow way of sending file.
+    # but in productions this code should not be called.
+    open my $fh, "<" => $disk_file
+        or return LJ::Request::NOT_FOUND;
+    binmode $fh;
+    my $palette = undef;
+    if (%pal_colors) {
+        if ($opts->{'mime'} eq "image/gif") {
+            $palette = PaletteModify::new_gif_palette($fh, \%pal_colors);
+        } elsif ($opts->{'mime'} == "image/png") {
+            $palette = PaletteModify::new_png_palette($fh, \%pal_colors);
+        }
+        unless ($palette) {
+            return LJ::Request::NOT_FOUND;  # image isn't palette changeable?
+        }
+    }
+    LJ::Request->print($palette) if $palette;
+    while (my $readed = read($fh, my $buf, 1024*1024)){
+        LJ::Request->print($buf);
+    }
+    close $fh;
+
+=head
     my $fh = Apache::File->new($disk_file);
-    return 404 unless $fh;
+    return LJ::Request::NOT_FOUND unless $fh;
     binmode($fh);
 
     my $palette;
@@ -141,14 +164,15 @@
             $palette = PaletteModify::new_png_palette($fh, \%pal_colors);
         }
         unless ($palette) {
-            return 404;  # image isn't palette changeable?
+            return LJ::Request::NOT_FOUND;  # image isn't palette changeable?
         }
     }
 
     $r->print($palette) if $palette; # when palette modified.
     $r->send_fd($fh); # sends remaining data (or all of it) quickly
     $fh->close();
-    return OK;
+=cut
+    return LJ::Request::OK;
 }
 
 1;

Modified: trunk/cgi-bin/Apache/LiveJournal.pm
===================================================================
--- trunk/cgi-bin/Apache/LiveJournal.pm	2010-01-25 07:57:58 UTC (rev 16124)
+++ trunk/cgi-bin/Apache/LiveJournal.pm	2010-01-25 08:24:36 UTC (rev 16125)
@@ -6,9 +6,10 @@
 use strict;
 no warnings 'uninitialized';
 
-use Apache::Constants qw(:common REDIRECT HTTP_NOT_MODIFIED
-                         HTTP_MOVED_PERMANENTLY HTTP_MOVED_TEMPORARILY
-                         M_TRACE M_OPTIONS);
+use LJ::Request;
+#use Apache::Constants qw(:common REDIRECT HTTP_NOT_MODIFIED
+#                         HTTP_MOVED_PERMANENTLY HTTP_MOVED_TEMPORARILY
+#                         M_TRACE M_OPTIONS);
 use Apache::File ();
 use lib "$ENV{LJHOME}/cgi-bin";
 
@@ -37,7 +38,6 @@
 # load.  in non-apache mode, they're loaded via LJ::ModuleCheck->have
 use Class::Autouse qw(
                       Compress::Zlib
-                      XMLRPC::Transport::HTTP
                       LJ::URI
                       );
 
@@ -88,20 +88,26 @@
 # init handler (PostReadRequest)
 sub handler
 {
-    my $r = shift;
+    my $class = ();
+    my $r     = shift; # 
 
+    LJ::Request->free();
+    LJ::Request->init($r);
+
+    $class = __PACKAGE__ unless $class;
+
     if ($LJ::SERVER_TOTALLY_DOWN) {
-        $r->handler("perl-script");
-        $r->set_handlers(PerlHandler => [ \&totally_down_content ]);
-        return OK;
+        LJ::Request->handler("perl-script");
+        LJ::Request->set_handlers(PerlHandler => [ \&totally_down_content ]);
+        return LJ::Request::OK;
     }
 
     # only perform this once in case of internal redirects
-    if ($r->is_initial_req) {
-        $r->push_handlers(PerlCleanupHandler => sub { %RQ = () });
-        $r->push_handlers(PerlCleanupHandler => "Apache::LiveJournal::db_logger");
-        $r->push_handlers(PerlCleanupHandler => "LJ::end_request");
-        $r->push_handlers(PerlCleanupHandler => "Apache::DebateSuicide");
+    if (LJ::Request->is_initial_req) {
+        LJ::Request->push_handlers(PerlCleanupHandler => sub { %RQ = () });
+        LJ::Request->push_handlers(PerlCleanupHandler => "Apache::LiveJournal::db_logger");
+        LJ::Request->push_handlers(PerlCleanupHandler => "LJ::end_request");
+        LJ::Request->push_handlers(PerlCleanupHandler => "Apache::DebateSuicide");
 
         if ($LJ::TRUST_X_HEADERS) {
             # if we're behind a lite mod_proxy front-end, we need to trick future handlers
@@ -109,8 +115,8 @@
             # by the fact that mod_proxy did nothing, requiring mod_proxy_add_forward, then
             # decided to do X-Forwarded-For, then did X-Forwarded-Host, so we have to deal
             # with all permutations of versions, hence all the ugliness:
-            @req_hosts = ($r->connection->remote_ip);
-            if (my $forward = $r->header_in('X-Forwarded-For'))
+            @req_hosts = (LJ::Request->remote_ip);
+            if (my $forward = LJ::Request->header_in('X-Forwarded-For'))
             {
                 my (@hosts, %seen);
                 foreach (split(/\s*,\s*/, $forward)) {
@@ -120,16 +126,16 @@
                 }
                 if (@hosts) {
                     my $real = shift @hosts;
-                    $r->connection->remote_ip($real);
+                    LJ::Request->remote_ip($real);
                 }
-                $r->header_in('X-Forwarded-For', join(", ", @hosts));
+                LJ::Request->header_in('X-Forwarded-For', join(", ", @hosts));
             }
 
             # and now, deal with getting the right Host header
-            if ($_ = $r->header_in('X-Host')) {
-                $r->header_in('Host', $_);
-            } elsif ($_ = $r->header_in('X-Forwarded-Host')) {
-                $r->header_in('Host', $_);
+            if ($_ = LJ::Request->header_in('X-Host')) {
+                LJ::Request->header_in('Host', $_);
+            } elsif ($_ = LJ::Request->header_in('X-Forwarded-Host')) {
+                LJ::Request->header_in('Host', $_);
             }
         }
 
@@ -170,64 +176,67 @@
         LJ::work_report_start();
     }
 
-    $r->set_handlers(PerlTransHandler => [ \&trans ]);
+    LJ::Request->set_handlers(PerlTransHandler => [ \&trans ]);
 
-    return OK;
+    return LJ::Request::OK;
 }
 
 sub redir {
-    my ($r, $url, $code) = @_;
-    $r->content_type("text/html");
-    $r->header_out(Location => $url);
+    # TODO: remove debug code
+    if (@_ == 3){
+        require Carp;
+        Carp::cluck("get 3 args instead of 2");
+        shift @_; # assumes the first arg is a Apache->request obj. 
+    }
+    
+    my ($url, $code) = @_;
+    LJ::Request->content_type("text/html");
+    LJ::Request->header_out(Location => $url);
     if ($LJ::DEBUG{'log_redirects'}) {
-        $r->log_error("redirect to $url from: " . join(", ", caller(0)));
+        LJ::Request->log_error("redirect to $url from: " . join(", ", caller(0)));
     }
-    return $code || REDIRECT;
+    return $code || LJ::Request::REDIRECT;
 }
 
 # send the user to the URL for them to get their domain session cookie
 sub remote_domsess_bounce {
-    my $r = Apache->request;
-    return redir($r, LJ::remote_bounce_url(), HTTP_MOVED_TEMPORARILY);
+    return redir(LJ::remote_bounce_url(), LJ::Request::HTTP_MOVED_TEMPORARILY);
 }
 
 sub totally_down_content
 {
-    my $r = shift;
-    my $uri = $r->uri;
+    my $uri = LJ::Request->uri;
 
     if ($uri =~ m!^/interface/flat! || $uri =~ m!^/cgi-bin/log\.cg!) {
-        $r->content_type("text/plain");
-        $r->send_http_header();
-        $r->print("success\nFAIL\nerrmsg\n$LJ::SERVER_DOWN_MESSAGE");
-        return OK;
+        LJ::Request->content_type("text/plain");
+        LJ::Request->send_http_header();
+        LJ::Request->print("success\nFAIL\nerrmsg\n$LJ::SERVER_DOWN_MESSAGE");
+        return LJ::Request::OK;
     }
 
     if ($uri =~ m!^/customview.cgi!) {
-        $r->content_type("text/html");
-        $r->send_http_header();
-        $r->print("<!-- $LJ::SERVER_DOWN_MESSAGE -->");
-        return OK;
+        LJ::Request->content_type("text/html");
+        LJ::Request->send_http_header();
+        LJ::Request->print("<!-- $LJ::SERVER_DOWN_MESSAGE -->");
+        return LJ::Request::OK;
     }
 
     # set to 500 so people don't cache this error message
     my $body = "<h1>$LJ::SERVER_DOWN_SUBJECT</h1>$LJ::SERVER_DOWN_MESSAGE<!-- " . ("x" x 1024) . " -->";
-    $r->status_line("503 Server Maintenance");
-    $r->content_type("text/html");
-    $r->header_out("Content-length", length $body);
-    $r->send_http_header();
+    LJ::Request->status_line("503 Server Maintenance");
+    LJ::Request->content_type("text/html");
+    LJ::Request->header_out("Content-length", length $body);
+    LJ::Request->send_http_header();
 
-    $r->print($body);
-    return OK;
+    LJ::Request->print($body);
+    return LJ::Request::OK;
 }
 
 sub blocked_bot
 {
-    my $r = shift;
-
-    $r->status_line("403 Denied");
-    $r->content_type("text/html");
-    $r->send_http_header();
+    LJ::Request->status_line("403 Denied");
+    LJ::Request->content_type("text/html");
+    LJ::Request->send_http_header();
     my $subject = $LJ::BLOCKED_BOT_SUBJECT || "403 Denied";
     my $message = $LJ::BLOCKED_BOT_MESSAGE || "You don't have permission to view this page.";
 
@@ -237,31 +246,34 @@
         $message .= " $uniq @ $ip";
     }
 
-    $r->print("<h1>$subject</h1>$message");
-    return OK;
+    LJ::Request->print("<h1>$subject</h1>$message");
+    return LJ::Request::OK;
 }
 
 sub trans
 {
-    my $r = shift;
-    return DECLINED if ! $r->is_main || $r->method_number == M_OPTIONS;  # don't deal with subrequests or OPTIONS
+    return LJ::Request::DECLINED 
+        if ! LJ::Request->is_main || LJ::Request->method_number == LJ::Request->M_OPTIONS;  # don't deal with subrequests or OPTIONS
 
-    my $uri = $r->uri;
-    my $args = $r->args;
+    my $uri  = LJ::Request->uri;
+    my $args = LJ::Request->args;
     my $args_wq = $args ? "?$args" : "";
-    my $host = $r->header_in("Host");
+    my $host = LJ::Request->header_in("Host");
+warn "HOST: $host";
+warn "URI: " . LJ::Request->uri;
+warn "Filename: " . LJ::Request->filename;
     my $hostport = ($host =~ s/:\d+$//) ? $& : "";
     $host =~ s/\.$//; ## 'www.livejournal.com.' is a valid DNS hostname
-    
+
     # disable TRACE (so scripts on non-LJ domains can't invoke
     # a trace to get the LJ cookies in the echo)
-    return FORBIDDEN if $r->method_number == M_TRACE;
+    return LJ::Request::FORBIDDEN if LJ::Request->method_number == LJ::Request::M_TRACE;
 
     # If the configuration says to log statistics and GTop is available, mark
     # values before the request runs so it can be turned into a delta later
     if (my $gtop = LJ::gtop()) {
-        $r->pnotes( 'gtop_cpu' => $gtop->cpu );
-        $r->pnotes( 'gtop_mem' => $gtop->proc_mem($$) );
+        LJ::Request->pnotes( 'gtop_cpu' => $gtop->cpu );
+        LJ::Request->pnotes( 'gtop_mem' => $gtop->proc_mem($$) );
     }
 
     LJ::start_request();
@@ -271,19 +283,19 @@
     my $lang = $LJ::DEFAULT_LANG || $LJ::LANGS[0];
     BML::set_language($lang, \&LJ::Lang::get_text);
 
-    my $is_ssl = $LJ::IS_SSL = LJ::run_hook("ssl_check", {
-        r => $r,
-    });
+    my $is_ssl = $LJ::IS_SSL = LJ::run_hook("ssl_check");
 
+#=head
     my $bml_handler = sub {
         my $filename = shift;
-        $r->handler("perl-script");
-        $r->notes("bml_filename" => $filename);
-        $r->push_handlers(PerlHandler => \&Apache::BML::handler);
-        return OK;
+warn "BML HANDLER: filename=$filename";
+        LJ::Request->handler("perl-script");
+        LJ::Request->notes("bml_filename" => $filename);
+        LJ::Request->push_handlers(PerlHandler => \&Apache::BML::handler);
+        return LJ::Request::OK;
     };
 
-    if ($r->is_initial_req) {
+    if (LJ::Request->is_initial_req) {
         # delete cookies if there are any we want gone
         if (my $cookie = $LJ::DEBUG{"delete_cookie"}) {
             LJ::Session::set_cookie($cookie => 0, delete => 1, domain => $LJ::DOMAIN, path => "/");
@@ -298,13 +310,13 @@
 
               # apply sysban block if applicable
               if (LJ::UniqCookie->sysban_should_block) {
-                  $r->handler("perl-script");
-                  $r->push_handlers(PerlHandler => \&blocked_bot );
-                  return OK;
+                  LJ::Request->handler("perl-script");
+                  LJ::Request->push_handlers(PerlHandler => \&blocked_bot );
+                  return LJ::Request::OK;
               }
           }
     } else { # not is_initial_req
-        if ($r->status == 404) {
+        if (LJ::Request->status == 404) {
             my $fn = $LJ::PAGE_404 || "404-error.html";
             return $bml_handler->("$LJ::HOME/htdocs/" . $fn);
         }
@@ -315,18 +327,18 @@
     unless ( $LJ::BLOCKED_BOT_URI && index( $uri, $LJ::BLOCKED_BOT_URI ) == 0 ) {
         foreach my $ip (@req_hosts) {
             if (LJ::sysban_check('ip', $ip)) {
-                $r->handler("perl-script");
-                $r->push_handlers(PerlHandler => \&blocked_bot );
-                return OK;
+                LJ::Request->handler("perl-script");
+                LJ::Request->push_handlers(PerlHandler => \&blocked_bot );
+                return LJ::Request::OK;
             }
         }
-        if (LJ::run_hook("forbid_request", $r)) {
-            $r->handler("perl-script");
-            $r->push_handlers(PerlHandler => \&blocked_bot );
-            return OK;
+        if (LJ::run_hook("forbid_request")) {
+            LJ::Request->handler("perl-script");
+            LJ::Request->push_handlers(PerlHandler => \&blocked_bot );
+            return LJ::Request::OK
         }
     }
-    
+
     # only allow certain pages over SSL
     if ($is_ssl) {
         if ($uri =~ m!^/interface/! || $uri =~ m!^/__rpc_!) {
@@ -335,16 +347,16 @@
             my $file = "$LJ::SSLDOCS/$uri";
             unless (-e $file) {
                 # no such file.  send them to the main server if it's a GET.
-                return $r->method eq 'GET' ? redir($r, "$LJ::SITEROOT$uri$args_wq") : 404;
+                return LJ::Request->method eq 'GET' ? redir("$LJ::SITEROOT$uri$args_wq") : 404;
             }
             if (-d _) { $file .= "/index.bml"; }
             $file =~ s!/{2,}!/!g;
-            $r->filename($file);
+            LJ::Request->filename($file);
             $LJ::IMGPREFIX = "/img";
             $LJ::STATPREFIX = "/stc";
-            return OK;
+            return LJ::Request::OK
         } else {
-            return FORBIDDEN;
+            return LJ::Request::FORBIDDEN;
         }
     } elsif (LJ::run_hook("set_alternate_statimg")) {
         # do nothing, hook did it.
@@ -356,32 +368,33 @@
     }
 
     # let foo.com still work, but redirect to www.foo.com
-    if ($LJ::DOMAIN_WEB && $r->method eq "GET" &&
+    if ($LJ::DOMAIN_WEB && LJ::Request->method eq "GET" &&
         $host eq $LJ::DOMAIN && $LJ::DOMAIN_WEB ne $LJ::DOMAIN)
     {
+warn "REDIRECT TO SITEROOT";
         my $url = "$LJ::SITEROOT$uri";
         $url .= "?" . $args if $args;
-        return redir($r, $url);
+        return redir($url);
     }
 
     # see if we should setup a minimal scheme based on the initial part of the
     # user-agent string; FIXME: maybe this should do more than just look at the
     # initial letters?
-    if (my $ua = $r->header_in('User-Agent')) {
+    if (my $ua = LJ::Request->header_in('User-Agent')) {
         if (($ua =~ /^([a-z]+)/i) && $LJ::MINIMAL_USERAGENT{$1}) {
-            $r->notes('use_minimal_scheme' => 1);
-            $r->notes('bml_use_scheme' => $LJ::MINIMAL_BML_SCHEME);
+            LJ::Request->notes('use_minimal_scheme' => 1);
+            LJ::Request->notes('bml_use_scheme' => $LJ::MINIMAL_BML_SCHEME);
         }
     }
 
     # now we know that the request is going to succeed, so do some checking if they have a defined
     # referer.  clients and such don't, so ignore them.
-    my $referer = $r->header_in("Referer");
-    if ($referer && $r->method eq 'POST' && !LJ::check_referer('', $referer)) {
-       $r->log_error("REFERER WARNING: POST to $uri from $referer");
+    my $referer = LJ::Request->header_in("Referer");
+    if ($referer && LJ::Request->method eq 'POST' && !LJ::check_referer('', $referer)) {
+       LJ::Request->log_error("REFERER WARNING: POST to $uri from $referer");
     }
 
-    my %GET = $r->args;
+    my %GET = LJ::Request->args;
 
     if ($LJ::IS_DEV_SERVER && $GET{'as'} =~ /^\w{1,15}$/) {
         my $ru = LJ::load_user($GET{'as'});
@@ -389,8 +402,8 @@
     }
 
     # anti-squatter checking
-    if ($LJ::DEBUG{'anti_squatter'} && $r->method eq "GET") {
-        my $ref = $r->header_in("Referer");
+    if ($LJ::DEBUG{'anti_squatter'} && LJ::Request->method eq "GET") {
+        my $ref = LJ::Request->header_in("Referer");
         if ($ref && index($ref, $LJ::SITEROOT) != 0) {
             # FIXME: this doesn't anti-squat user domains yet
             if ($uri !~ m!^/404!) {
@@ -401,10 +414,10 @@
                 # FIXME: why??  why doesn't it just work to return OK
                 # the first time with the handlers pushed?  nothing
                 # else requires this chicanery!
-                $r->handler("perl-script");
-                $r->push_handlers(PerlHandler => \&anti_squatter);
+                LJ::Request->handler("perl-script");
+                LJ::Request->push_handlers(PerlHandler => \&anti_squatter);
             }
-            return OK;
+            return LJ::Request::OK
         }
     }
 
@@ -414,14 +427,15 @@
     }
 
     # allow html pages (with .html extention) in user domains and in common www. domain.
-    if ($r->uri =~ m|\A\/__html(\/.+\.html)\z|){
-        $r->uri($1);
-        return DECLINED;
+    if (LJ::Request->uri =~ m|\A\/__html(\/.+\.html)\z|){
+        LJ::Request->uri($1);
+        return LJ::Request::DECLINED
     }
 
     my $journal_view = sub {
         my $opts = shift;
         $opts ||= {};
+warn "Journal view";
 
         my $orig_user = $opts->{'user'};
         $opts->{'user'} = LJ::canonical_username($opts->{'user'});
@@ -445,7 +459,7 @@
             # consistent for the concatenation before redirect
             $newurl =~ s!^/(users/|community/|~)\Q$orig_user\E!/!;
             $newurl = LJ::journal_base($u) . "$newurl$args_wq";
-            return redir($r, $newurl);
+            return redir($newurl);
         }
 
         # check if this entry or journal contains adult content
@@ -483,7 +497,7 @@
             my $is_journal_page = !$opts->{mode} || $journal_pages{$opts->{mode}};
 
             if ($adult_content ne "none" && $is_journal_page && !$should_show_page) {
-                my $returl = LJ::eurl("http://$host" . $r->uri . "$args_wq");
+                my $returl = LJ::eurl("http://$host" . LJ::Request->uri . "$args_wq");
 
                 LJ::ContentFlag->check_adult_cookie($returl, \%BMLCodeBlock::POST, "concepts");
                 LJ::ContentFlag->check_adult_cookie($returl, \%BMLCodeBlock::POST, "explicit");
@@ -499,14 +513,14 @@
                 # logged in users without defined ages and logged out users are given confirmation pages (unless they have already confirmed)
                 if ($remote) {
                     if (($adult_content eq "explicit" && $remote->is_minor) || ($adult_content eq "concepts" && $remote->is_child)) {
-                        $r->args("user=" . LJ::eurl($opts->{'user'}));
+                        LJ::Request->args("user=" . LJ::eurl($opts->{'user'}));
                         return $bml_handler->(LJ::ContentFlag->adult_interstitial_path(type => "${adult_content}_blocked"));
                     } elsif (!$remote->best_guess_age && !$cookie) {
-                        $r->args("ret=$returl&user=" . LJ::eurl($opts->{'user'}));
+                        LJ::Request->args("ret=$returl&user=" . LJ::eurl($opts->{'user'}));
                         return $bml_handler->(LJ::ContentFlag->adult_interstitial_path(type => $adult_content));
                     }
                 } elsif (!$remote && !$cookie) {
-                    $r->args("ret=$returl&user=" . LJ::eurl($opts->{'user'}));
+                    LJ::Request->args("ret=$returl&user=" . LJ::eurl($opts->{'user'}));
                     return $bml_handler->(LJ::ContentFlag->adult_interstitial_path(type => $adult_content));
                 }
             }
@@ -514,16 +528,16 @@
 
         if ($opts->{'mode'} eq "info") {
             my $u = LJ::load_user($opts->{user})
-                or return 404;
+                or return LJ::Request::NOT_FOUND;
             my $mode = $GET{mode} eq 'full' ? '?mode=full' : '';
-            return redir($r, $u->profile_url . $mode);
+            return redir($u->profile_url . $mode);
         }
 
         if ($opts->{'mode'} eq "profile") {
             my $burl = LJ::remote_bounce_url();
             return remote_domsess_bounce() if LJ::remote_bounce_url();
 
-            $r->notes("_journal" => $opts->{'user'});
+            LJ::Request->notes("_journal" => $opts->{'user'});
 
             # this is the notes field that all other s1/s2 pages use.
             # so be consistent for people wanting to read it.
@@ -532,7 +546,7 @@
             # passed to the userinfo BML page, whereas this one only
             # works if journalid exists.
             if (my $u = LJ::load_user($opts->{user})) {
-                $r->notes("journalid" => $u->{userid});
+                LJ::Request->notes("journalid" => $u->{userid});
             }
 
             my $file = LJ::run_hook("profile_bml_file");
@@ -545,9 +559,9 @@
 
         if ($opts->{'mode'} eq "update") {
             my $u = LJ::load_user($opts->{user})
-                or return 404;
+                or return LJ::Request::NOT_FOUND;
 
-            return redir($r, "$LJ::SITEROOT/update.bml?usejournal=".$u->{'user'});
+            return redir("$LJ::SITEROOT/update.bml?usejournal=".$u->{'user'});
         }
 
         %RQ = %$opts;
@@ -559,20 +573,20 @@
 
             my ($mode, $path) = ($1, $2);
             if ($mode eq "customview") {
-                $r->handler("perl-script");
-                $r->push_handlers(PerlHandler => \&customview_content);
-                return OK;
+                LJ::Request->handler("perl-script");
+                LJ::Request->push_handlers(PerlHandler => \&customview_content);
+                return LJ::Request::OK
             }
             if (my $handler = LJ::run_hook("data_handler:$mode", $RQ{'user'}, $path)) {
-                $r->handler("perl-script");
-                $r->push_handlers(PerlHandler => $handler);
-                return OK;
+                LJ::Request->handler("perl-script");
+                LJ::Request->push_handlers(PerlHandler => $handler);
+                return LJ::Request::OK
             }
         }
 
-        $r->handler("perl-script");
-        $r->push_handlers(PerlHandler => \&journal_content);
-        return OK;
+        LJ::Request->handler("perl-script");
+        LJ::Request->push_handlers(PerlHandler => \&journal_content);
+        return LJ::Request::OK
     };
 
     my $determine_view = sub {
@@ -580,22 +594,23 @@
         my $mode = undef;
         my $pe;
         my $ljentry;
+warn "Determine view: uuri=$uuri";
 
         # if favicon, let filesystem handle it, for now, until
         # we have per-user favicons.
-        return DECLINED if $uuri eq "/favicon.ico";
+        return LJ::Request::DECLINED if $uuri eq "/favicon.ico";
 
         # see if there is a modular handler for this URI
-        my $ret = LJ::URI->handle($uuri, $r);
+        my $ret = LJ::URI->handle($uuri, LJ::Request->r);
         return $ret if defined $ret;
 
         if ($uuri eq "/__setdomsess") {
-            return redir($r, LJ::Session->setdomsess_handler($r));
+            return redir(LJ::Session->setdomsess_handler());
         }
 
         if ($uuri =~ m#^/(\d+)\.html$#) {
             my $u = LJ::load_user($user)
-                or return 404;
+                or return LJ::Request::NOT_FOUND;
 
             $ljentry = LJ::Entry->new($u, ditemid => $1);
             if ($GET{'mode'} eq "reply" || $GET{'replyto'} || $GET{'edit'}) {
@@ -607,12 +622,12 @@
             my ($year, $mon, $day, $slash) = ($1, $2, $3, $4);
             unless ($slash) {
                 my $u = LJ::load_user($user)
-                    or return 404;
+                    or return LJ::Request::NOT_FOUND;
                 my $proper = $u->journal_base . "/$year";
                 $proper .= "/$mon" if defined $mon;
                 $proper .= "/$day" if defined $day;
                 $proper .= "/";
-                return redir($r, $proper);
+                return redir($proper);
             }
 
             # the S1 ljviews code looks at $opts->{'pathextra'}, because
@@ -639,18 +654,18 @@
             if ($mode =~ /^day|calendar$/ && $pe =~ m!^/\d\d\d\d!) {
                 my $newuri = $uri;
                 $newuri =~ s!$mode/(\d\d\d\d)!$1!;
-                return redir($r, LJ::journal_base($user) . $newuri);
+                return redir(LJ::journal_base($user) . $newuri);
             } elsif ($mode eq 'rss') {
                 # code 301: moved permanently, update your links.
-                return redir($r, LJ::journal_base($user) . "/data/rss$args_wq", 301);
+                return redir(LJ::journal_base($user) . "/data/rss$args_wq", 301);
             } elsif ($mode eq 'pics' && $LJ::REDIRECT_ALLOWED{$LJ::FB_DOMAIN}) {
                 # redirect to a user's gallery
                 my $url = "$LJ::FB_SITEROOT/$user";
-                return redir($r, $url);
+                return redir($url);
             } elsif ($mode eq 'tag') {
 
                 # tailing slash on here to prevent a second redirect after this one
-                return redir($r, LJ::journal_base($user) . "$uri/") unless $pe;
+                return redir(LJ::journal_base($user) . "$uri/") unless $pe;
                 if ($pe eq '/') {
                     # tag list page
                     $mode = 'tag';
@@ -664,10 +679,10 @@
                 }
             } elsif ($mode eq 'security') {
                 # tailing slash on here to prevent a second redirect after this one
-                return redir($r, LJ::journal_base($user) . "$uri/") unless $pe;
+                return redir(LJ::journal_base($user) . "$uri/") unless $pe;
                 if ($pe eq '/') {
                     # do a 404 for now
-                    return 404;
+                    return LJ::Request::NOT_FOUND;
                 } else {
                     # filtered lastn page
                     $mode = 'lastn';
@@ -683,7 +698,7 @@
             my $key = $uuri;
             $key =~ s!^/!!;
             my $u = LJ::load_user($user)
-                or return 404;
+                or return LJ::Request::NOT_FOUND;
 
             my ($type, $nodeid)...
 (truncated)
Tags: bml, livejournal, look, pl, pm, vadvs
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments