diff --git a/cgi-bin/Apache/LiveJournal.pm b/cgi-bin/Apache/LiveJournal.pm index a199be9d85..19ff0ce5cb 100644 --- a/cgi-bin/Apache/LiveJournal.pm +++ b/cgi-bin/Apache/LiveJournal.pm @@ -1042,67 +1042,25 @@ sub userpic_trans return OK; } -sub userpic_content -{ - my $apache_r = shift; - my $file = $apache_r->filename; - - my $picid = $RQ{'picid'}; - my $userid = $RQ{'pic-userid'}+0; - - my ($data, $lastmod); - - my $mime = "image/jpeg"; - my $set_mime = sub { - my $data = shift; - if ($data =~ /^GIF/) { $mime = "image/gif"; } - elsif ($data =~ /^\x89PNG/) { $mime = "image/png"; } - }; - my $size; - - my $send_headers = sub { - $size = $_[0] if @_; - $size ||= 0; - $apache_r->content_type( $mime ); - $apache_r->headers_out->{"Content-length"} = $size + 0; - $apache_r->headers_out->{"Cache-Control"} = "no-transform"; - $apache_r->headers_out->{"Last-Modified"} = LJ::time_to_http($lastmod); - }; +sub userpic_content { + my $apache_r = $_[0]; # Load the user object and pic and make sure the picture is viewable - my $u = LJ::load_userid($userid); - my $pic = LJ::Userpic->get( $u, $picid, { no_expunged => 1 } ) + my $u = LJ::load_userid( $RQ{'pic-userid'} ); + my $pic = LJ::Userpic->get( $u, $RQ{'picid'}, { no_expunged => 1 } ) or return NOT_FOUND; - # Read the mimetype from the pichash if dversion 7 - $mime = $pic->mimetype; - - ### Handle reproxyable requests - - # For dversion 7+ and mogilefs userpics, follow this path - if ( $pic->in_mogile ) { - my $key = $u->mogfs_userpic_key( $picid ); - my $memkey = [$picid, "mogp.up.$picid"]; - mogile_fetch( $apache_r, $key, $memkey, 'userpics', $send_headers ); - return OK; - } - - # else, get it from db. - unless ($data) { - $lastmod = $pic->pictime; - - my $dbb = LJ::get_cluster_reader( $u ); - return SERVER_ERROR unless $dbb; - $data = $dbb->selectrow_array( "SELECT imagedata FROM userpicblob2 WHERE " . - "userid=$userid AND picid=$picid" ); - } - + # Must have contents by now, or return 404 + my $data = $pic->imagedata; return NOT_FOUND unless $data; - $set_mime->($data); - $size = length($data); - $send_headers->(); - $apache_r->print($data) unless $apache_r->header_only; + # Everything looks good, send it + $apache_r->content_type( $pic->mimetype ); + $apache_r->headers_out->{"Content-length"} = length $data; + $apache_r->headers_out->{"Cache-Control"} = "no-transform"; + $apache_r->headers_out->{"Last-Modified"} = LJ::time_to_http( $pic->pictime ); + $apache_r->print( $data ) + unless $apache_r->header_only; return OK; } @@ -1143,9 +1101,8 @@ sub vgift_trans return OK; } -sub vgift_content -{ - my $apache_r = shift; +sub vgift_content { + my $apache_r = $_[0]; my $picid = $RQ{picid}; my $picsize = $RQ{picsize}; @@ -1154,7 +1111,6 @@ sub vgift_content return NOT_FOUND unless $mime; my $size; - my $send_headers = sub { $size = $_[0] if @_; $size ||= 0; @@ -1164,8 +1120,12 @@ sub vgift_content }; my $key = $vg->img_mogkey( $picsize ); - my $memkey = $vg->img_memkey( $picsize ); #[$picid, "mogp.vg.$picsize.$picid"]; - mogile_fetch( $apache_r, $key, $memkey, 'vgifts', $send_headers ); + my $data = LJ::mogclient()->get_file_data( $key ); + return NOT_FOUND unless $data; + + $send_headers->( length $$data ); + $apache_r->print( $$data ) + unless $apache_r->header_only; return OK; } @@ -1454,45 +1414,6 @@ sub interface_content return OK; } -sub mogile_fetch { - my ( $apache_r, $key, $memkey, $class, $send_headers ) = @_; - - if ( !$LJ::REPROXY_DISABLE{$class} && - $apache_r->headers_in->{'X-Proxy-Capabilities'} && - $apache_r->headers_in->{'X-Proxy-Capabilities'} =~ m{\breproxy-file\b}i ) { - - my $zone = $apache_r->headers_in->{'X-MogileFS-Explicit-Zone'} || undef; - $memkey->[1] .= ".$zone" if $zone; - - my $cache_for = $LJ::MOGILE_PATH_CACHE_TIMEOUT || 3600; - - my $paths = LJ::MemCache::get( $memkey ); - unless ( $paths ) { - # load and add to memcache - my @paths = LJ::mogclient()->get_paths( $key, { noverify => 1, zone => $zone } ); - $paths = \@paths; - LJ::MemCache::add( $memkey, $paths, $cache_for ) if @paths; - } - - if ( defined $paths->[0] && $paths->[0] =~ m/^https?:/ ) { - # reproxy url - $apache_r->headers_out->{'X-REPROXY-CACHE-FOR'} = "$cache_for; Last-Modified Content-Type"; - $apache_r->headers_out->{'X-REPROXY-URL'} = join( ' ', @$paths ); - } else { - # reproxy file - $apache_r->headers_out->{'X-REPROXY-FILE'} = $paths->[0]; - } - - $send_headers->(); - - } else { # no reproxy - my $data = LJ::mogclient()->get_file_data( $key ); - return NOT_FOUND unless $data; - $send_headers->( length $$data ); - $apache_r->print( $$data ) unless $apache_r->header_only; - } -} - package LJ::Protocol; use Encode(); diff --git a/cgi-bin/DW/Controller/Media.pm b/cgi-bin/DW/Controller/Media.pm index 62ed8caea8..6b326648b7 100644 --- a/cgi-bin/DW/Controller/Media.pm +++ b/cgi-bin/DW/Controller/Media.pm @@ -159,7 +159,6 @@ sub media_handler { unless $obj->visible_to( LJ::get_remote() ); # load the data for this object -# FIXME: support X-REPROXY headers here my $dataref = LJ::mogclient()->get_file_data( $obj->mogkey ); return $error_out->( 500, 'Unexpected internal error locating file' ) unless defined $dataref && ref $dataref eq 'SCALAR'; diff --git a/cgi-bin/LJ/ConfCheck/General.pm b/cgi-bin/LJ/ConfCheck/General.pm index 5c7e66f3bf..5d485426d6 100644 --- a/cgi-bin/LJ/ConfCheck/General.pm +++ b/cgi-bin/LJ/ConfCheck/General.pm @@ -430,10 +430,6 @@ add_conf('$MEMCACHE_CB_CONNECT_FAIL', des => "Callback when a connection to a memcached instance fails. Subref gets the IP address that was being connected to, but without the port number." ); -add_conf('%REPROXY_DISABLE', - des => "Set of file classes that shouldn't be internally redirected to mogstored nodes. Values are true, keys are one of 'userpics', or site-local file types like 'phoneposts' for ljcom. Seee also \%USERPIC_REPROXY_DISABLE" - ); - add_conf('$SQUAT_URL', des => "For anti-squatter checking in Apache/LiveJournal.pm." ); diff --git a/cgi-bin/LJ/Global/Defaults.pm b/cgi-bin/LJ/Global/Defaults.pm index 073ca8d381..0a848ade55 100644 --- a/cgi-bin/LJ/Global/Defaults.pm +++ b/cgi-bin/LJ/Global/Defaults.pm @@ -195,10 +195,6 @@ no strict "vars"; $MOGILEFS_CONFIG{classes}->{vgifts} ||= 3; $MOGILEFS_CONFIG{classes}->{media} ||= 3; - # Default to allow all reproxying. - %REPROXY_DISABLE = () unless %REPROXY_DISABLE; - - # detect whether we are running on 32-bit architecture my $arch = ( length(pack "L!", 0) == 4 ) ? 1 : 0; if ( defined $ARCH32 ) { @@ -208,7 +204,6 @@ no strict "vars"; $ARCH32 = $arch; } - # setup default minimal style information $MINIMAL_USERAGENT{$_} ||= 1 foreach qw(Links Lynx w BlackBerry WebTV); # w is for w3m $MINIMAL_BML_SCHEME ||= 'lynx'; diff --git a/cgi-bin/LJ/User/Icons.pm b/cgi-bin/LJ/User/Icons.pm index 4a1c471602..15aee61341 100644 --- a/cgi-bin/LJ/User/Icons.pm +++ b/cgi-bin/LJ/User/Icons.pm @@ -746,7 +746,8 @@ sub get_userpic_kw_map { foreach my $keyword ( keys %{$picinfo->{kw}} ) { my $picid = $picinfo->{kw}->{$keyword}->{picid}; $keywords->{$picid} = [] unless $keywords->{$picid}; - push @{$keywords->{$picid}}, $keyword if ( defined( $keyword ) && $picid && $keyword !~ m/^pic\#(\d+)$/ ); + push @{$keywords->{$picid}}, $keyword + if defined $keyword && $picid && $keyword !~ m/^pic\#(\d+)$/; } return $u->{picid_kw_map} = $keywords;