diff options
author | Eric Wong <e@80x24.org> | 2017-12-08 20:54:09 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-12-08 20:55:33 +0000 |
commit | 144885c29120cd4e4e64d10f6c320f5efbf9fb7b (patch) | |
tree | 230f395da956e10df61098fe18fe5698ea38dc77 /lib/PublicInbox/WWW.pm | |
parent | cefae696bcce7ac04b762613b8936e2e446d6203 (diff) | |
download | public-inbox-144885c29120cd4e4e64d10f6c320f5efbf9fb7b.tar.gz |
This should prevent crawlers (including most robots.txt ignoring ones) from burning our CPU time without severely compromising usability for humans.
Diffstat (limited to 'lib/PublicInbox/WWW.pm')
-rw-r--r-- | lib/PublicInbox/WWW.pm | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index f3c702e9..3fd77d42 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -53,10 +53,14 @@ sub call { my $path_info = $env->{PATH_INFO}; my $method = $env->{REQUEST_METHOD}; - if ($method eq 'POST' && - $path_info =~ m!$INBOX_RE/(git-upload-pack)\z!) { - my $path = $2; - return invalid_inbox($ctx, $1) || serve_git($ctx, $path); + if ($method eq 'POST') { + if ($path_info =~ m!$INBOX_RE/(git-upload-pack)\z!) { + my $path = $2; + return invalid_inbox($ctx, $1) || + serve_git($ctx, $path); + } elsif ($path_info =~ m!$INBOX_RE/!o) { + return invalid_inbox($ctx, $1) || mbox_results($ctx); + } } elsif ($method !~ /\AGET|HEAD\z/) { return r(405, 'Method Not Allowed'); @@ -400,6 +404,16 @@ sub serve_git { PublicInbox::GitHTTPBackend::serve($ctx->{env}, $ctx->{git}, $path); } +sub mbox_results { + my ($ctx) = @_; + if ($ctx->{env}->{QUERY_STRING} =~ /(?:\A|[&;])q=/) { + searcher($ctx) or return need_search($ctx); + require PublicInbox::SearchView; + return PublicInbox::SearchView::mbox_results($ctx); + } + r404(); +} + sub serve_mbox_range { my ($ctx, $inbox, $range) = @_; invalid_inbox($ctx, $inbox) || eval { |