X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWWW.pm;h=1f3ca1574aa0c5c84c43dcc31d8797f08b6de5e6;hb=7a3946ef122e8218c6ce3355d7f968562212d53b;hp=798e8b17c04b007400db465ab84f0b889bec9972;hpb=3cf66514aea9e958999973b9f104473b6d800fbe;p=public-inbox.git diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 798e8b17..1f3ca157 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -11,7 +11,7 @@ # - Must not rely on static content # - UTF-8 is only for user-content, 7-bit US-ASCII for us package PublicInbox::WWW; -use 5.008; +use 5.010_001; use strict; use warnings; use bytes (); # only for bytes::length @@ -68,8 +68,9 @@ sub call { } split(/[&;]+/, $env->{QUERY_STRING}); $ctx->{qp} = \%qp; - # not using $env->{PATH_INFO} here since that's already decoded + # avoiding $env->{PATH_INFO} here since that's already decoded my ($path_info) = ($env->{REQUEST_URI} =~ path_re($env)); + $path_info //= $env->{PATH_INFO}; my $method = $env->{REQUEST_METHOD}; if ($method eq 'POST') { @@ -87,7 +88,7 @@ sub call { # top-level indices and feeds if ($path_info eq '/') { - r404(); + www_listing($self)->call($env); } elsif ($path_info =~ m!$INBOX_RE\z!o) { invalid_inbox($ctx, $1) || r301($ctx, $1); } elsif ($path_info =~ m!$INBOX_RE(?:/|/index\.html)?\z!o) { @@ -157,6 +158,7 @@ sub preload { if (ref($self)) { $self->cgit; $self->stylesheets_prepare($_) for ('', '../', '../../'); + $self->www_listing; } } @@ -186,10 +188,9 @@ sub news_cgit_fallback ($) { # returns undef if valid, array ref response if invalid sub invalid_inbox ($$) { my ($ctx, $inbox) = @_; - my $obj = $ctx->{www}->{pi_config}->lookup_name($inbox); - if (defined $obj) { - $ctx->{git} = $obj->git; - $ctx->{-inbox} = $obj; + my $ibx = $ctx->{www}->{pi_config}->lookup_name($inbox); + if (defined $ibx) { + $ctx->{-inbox} = $ibx; return; } @@ -403,13 +404,13 @@ sub legacy_redirects { sub r301 { my ($ctx, $inbox, $mid_ue, $suffix) = @_; - my $obj = $ctx->{-inbox}; - unless ($obj) { + my $ibx = $ctx->{-inbox}; + unless ($ibx) { my $r404 = invalid_inbox($ctx, $inbox); return $r404 if $r404; - $obj = $ctx->{-inbox}; + $ibx = $ctx->{-inbox}; } - my $url = $obj->base_url($ctx->{env}); + my $url = $ibx->base_url($ctx->{env}); my $qs = $ctx->{env}->{QUERY_STRING}; if (defined $mid_ue) { # common, and much nicer as '@' than '%40': @@ -490,6 +491,14 @@ sub cgit { } } +sub www_listing { + my ($self) = @_; + $self->{www_listing} ||= do { + require PublicInbox::WwwListing; + PublicInbox::WwwListing->new($self); + } +} + sub get_attach { my ($ctx, $idx, $fn) = @_; require PublicInbox::WwwAttach;