]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/HTTP.pm
www: fix absolute URLs when mounted under a subdir
[public-inbox.git] / lib / PublicInbox / HTTP.pm
index 5afe167e7578f140fb568373864d1e30d58c985d..009b5ff070725c7ce6555bd239e30bffb4360496 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Generic PSGI server for convenience.  It aims to provide
@@ -21,6 +21,7 @@ use IO::Handle;
 require PublicInbox::EvCleanup;
 use PublicInbox::DS qw(msg_more);
 use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
+use PublicInbox::Tmpfile;
 use constant {
        CHUNK_START => -1,   # [a-f0-9]+\r\n
        CHUNK_END => -2,     # \r\n
@@ -254,7 +255,7 @@ sub next_request ($) {
 sub response_done_cb ($$) {
        my ($self, $alive) = @_;
        sub {
-               my $env = delete $self->{env};
+               delete $self->{env}; # we're no longer busy
                $self->write(\"0\r\n\r\n") if $alive == 2;
                $self->write($alive ? \&next_request : \&close);
        }
@@ -325,8 +326,9 @@ sub response_write {
 }
 
 sub input_tmpfile ($) {
-       open($_[0], '+>', undef);
-       $_[0]->autoflush(1);
+       my $input = tmpfile('http.input', $_[0]->{sock}) or return;
+       $input->autoflush(1);
+       $input;
 }
 
 sub input_prepare {
@@ -338,10 +340,10 @@ sub input_prepare {
                        quit($self, 413);
                        return;
                }
-               input_tmpfile($input);
+               $input = input_tmpfile($self);
        } elsif (env_chunked($env)) {
                $len = CHUNK_START;
-               input_tmpfile($input);
+               $input = input_tmpfile($self);
        } else {
                $input = $null_io;
        }
@@ -451,9 +453,7 @@ sub quit {
 
 sub close {
        my $self = $_[0];
-       if (my $env = delete $self->{env}) {
-               delete $env->{'psgix.io'}; # prevent circular references
-       }
+       delete $self->{env}; # prevent circular references
        if (my $forward = delete $self->{forward}) {
                eval { $forward->close };
                err($self, "forward ->close error: $@") if $@;