# - 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
my $ctx = { env => $env, www => $self };
# we don't care about multi-value
- my %qp = map {
+ %{$ctx->{qp}} = map {
utf8::decode($_);
- my ($k, $v) = split('=', uri_unescape($_), 2);
- $v = '' unless defined $v;
- $v =~ tr/+/ /;
- ($k, $v)
+ tr/+/ /;
+ my ($k, $v) = split('=', $_, 2);
+ $v = uri_unescape($v // '');
+ # none of the keys we care about will need escaping
+ $k => $v;
} 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') {
# 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) {
if (ref($self)) {
$self->cgit;
$self->stylesheets_prepare($_) for ('', '../', '../../');
+ $self->www_listing;
}
}
# 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;
}
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':
}
}
+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;