]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
www: serve $INBOX_DIR/description as $INBOX_URL/description
[public-inbox.git] / lib / PublicInbox / WWW.pm
index 99f9f1dc258d2af531349e22eec173c64abd4119..02b5ded32e9a2950508ef39ef5d7697603eebf1b 100644 (file)
@@ -22,7 +22,7 @@ use PublicInbox::MID qw(mid_escape);
 require PublicInbox::Git;
 use PublicInbox::GitHTTPBackend;
 use PublicInbox::UserContent;
-use PublicInbox::WwwStatic qw(r);
+use PublicInbox::WwwStatic qw(r path_info_raw);
 
 # TODO: consider a routing tree now that we have more endpoints:
 our $INBOX_RE = qr!\A/([\w\-][\w\.\-]*)!;
@@ -43,19 +43,6 @@ sub run {
        PublicInbox::WWW->new->call($req->env);
 }
 
-# PATH_INFO is decoded, and we want the undecoded original
-my %path_re_cache;
-sub path_info_raw ($) {
-       my ($env) = @_;
-       my $sn = $env->{SCRIPT_NAME};
-       my $re = $path_re_cache{$sn} ||= do {
-               $sn = '/'.$sn unless index($sn, '/') == 0;
-               $sn =~ s!/\z!!;
-               qr!\A(?:https?://[^/]+)?\Q$sn\E(/[^\?\#]+)!;
-       };
-       $env->{REQUEST_URI} =~ $re ? $1 : $env->{PATH_INFO};
-}
-
 sub call {
        my ($self, $env) = @_;
        my $ctx = { env => $env, www => $self };
@@ -83,7 +70,7 @@ sub call {
                        return invalid_inbox($ctx, $1) || mbox_results($ctx);
                }
        }
-       elsif ($method !~ /\AGET|HEAD\z/) {
+       elsif ($method !~ /\A(?:GET|HEAD)\z/) {
                return r(405);
        }
 
@@ -98,6 +85,8 @@ sub call {
                invalid_inbox($ctx, $1) || get_atom($ctx);
        } elsif ($path_info =~ m!$INBOX_RE/new\.html\z!o) {
                invalid_inbox($ctx, $1) || get_new($ctx);
+       } elsif ($path_info =~ m!$INBOX_RE/description\z!o) {
+               get_description($ctx, $1);
        } elsif ($path_info =~ m!$INBOX_RE/(?:(?:git/)?([0-9]+)(?:\.git)?/)?
                                ($PublicInbox::GitHTTPBackend::ANY)\z!ox) {
                my ($epoch, $path) = ($2, $3);
@@ -634,4 +623,13 @@ sub get_css ($$$) {
        [ 200, $h, [ $css ] ];
 }
 
+sub get_description {
+       my ($ctx, $inbox) = @_;
+       invalid_inbox($ctx, $inbox) || do {
+               my $d = $ctx->{-inbox}->description . "\n";
+               [ 200, [ 'Content-Length', bytes::length($d),
+                       'Content-Type', 'text/plain' ], [ $d ] ];
+       };
+}
+
 1;