Selaa lähdekoodia

Prefer Sys::Hostname name, log when template writes happen in debug

George Baugh 2 vuotta sitten
vanhempi
sitoutus
b957831cc8
2 muutettua tiedostoa jossa 8 lisäystä ja 3 poistoa
  1. 3 1
      lib/TCMS.pm
  2. 5 2
      lib/Trog/Routes/HTML.pm

+ 3 - 1
lib/TCMS.pm

@@ -8,6 +8,7 @@ use feature qw{signatures state};
 
 use Date::Format qw{strftime};
 
+use Sys::Hostname();
 use HTTP::Body   ();
 use URL::Encode  ();
 use Text::Xslate ();
@@ -218,7 +219,7 @@ sub app {
     $query->{body}         = '';
     $query->{dnt}          = $env->{HTTP_DNT};
     $query->{user}         = $active_user;
-    $query->{domain}       = $env->{HTTP_X_FORWARDED_HOST} || $env->{HTTP_HOST};
+    $query->{domain}       = eval { Sys::Hostname::hostname() } // $env->{HTTP_X_FORWARDED_HOST} || $env->{HTTP_HOST};
     $query->{route}        = $path;
     $query->{scheme}       = $env->{'psgi.url_scheme'} // 'http';
     $query->{social_meta}  = 1;
@@ -267,6 +268,7 @@ sub _toolong() {
 
 sub _static ( $path, $start, $streaming, $last_fetch = 0 ) {
 
+    DEBUG("Rendering static for $path");
     # XXX because of psgi I can't just vomit the file directly
     if ( open( my $fh, '<', "www/statics/$path" ) ) {
         my $headers = '';

+ 5 - 2
lib/Trog/Routes/HTML.pm

@@ -1447,7 +1447,7 @@ sub finish_render ( $template, $vars, %headers ) {
 
     my $ct = 'Content-type';
     my $cc = 'Cache-control';
-    $headers{$ct}              = $vars->{contenttype};
+    $headers{$ct}              = $vars->{contenttype} // "text/html";
     $headers{$cc}              = $vars->{cachecontrol} if $vars->{cachecontrol};
     $headers{'Vary'}           = 'Accept-Encoding';
     $headers{"Content-Length"} = length($body);
@@ -1478,10 +1478,13 @@ sub finish_render ( $template, $vars, %headers ) {
 sub save_render ( $vars, $body, %headers ) {
     Path::Tiny::path( "www/statics/" . dirname( $vars->{route} ) )->mkpath;
     my $file = "www/statics/$vars->{route}";
+
+    my $verb = -f $file ? 'Overwrite' : 'Write';
+    DEBUG("$verb static for $vars->{route}");
     open( my $fh, '>', $file ) or die "Could not open $file for writing";
     print $fh "HTTP/1.1 $vars->{code} OK\n";
     foreach my $h ( keys(%headers) ) {
-        print $fh "$h:$headers{$h}\n";
+        print $fh "$h:$headers{$h}\n" if $headers{$h};
     }
     print $fh "\n";
     print $fh $body;