Hopefully this is the correct location for this post--if not I'll happily move it. I'm developing a web application in mod_perl that mostly works, except for two issues that I think are more apache related than perl related. The first issue is with an image displaying subroutine. With jpeg images everything works fine, the headers are sent correctly, and the image is displayed. However, with any other kind of image, the web server is writing out a 'text/html' header before the header I write. The perl handler code is drop dead simple: my $pic = $db->sql("select * from pictures where pic_key='$ui->{cgi}->{pic_key}';"); my $fs = -s $pic->[0]->{path}; print $ui->{cgi}->header('image/jpg') if ($pic->[0]->{path} =~ /\.jpg$/i); print $ui->{cgi}->header('image/png') if ($pic->[0]->{path} =~ /\.png$/i); if (($pic->[0]->{public} eq '0') && ($pic->[0]->{user_key} ne $ui->{state}->{USER_KEY})) { return 0; } $ui->{state}->{noresponse}=1; open(PIC, "$pic->[0]->{path}"); binmode(PIC); while(<PIC>) { print; } close(PIC); Code (markup): There are a few pieces of housekeeping in there, but that's it--send jpg headers when it's a jpg, and send png headers when it's a png. The issue is that jpg's render correctly, but png's are sent with a text/html header. Firebug tells me when I request a jpb I get: Response Headersview source Date Fri, 22 Jan 2010 21:15:16 GMT Server Apache Keep-Alive timeout=2, max=100 Connection Keep-Alive Transfer-Encoding chunked Content-Type image/jpg Code (markup): But for png's, I get: Response Headersview source Date Fri, 22 Jan 2010 21:15:53 GMT Server Apache Set-Cookie email=-redacted-; path=/; expires=Sat, 22-Jan-2011 21:15:53 GMT password1=-redacted-; path=/; expires=Sat, 22-Jan-2011 21:15:53 GMT Keep-Alive timeout=2, max=100 Connection Keep-Alive Transfer-Encoding chunked Content-Type text/html; charset=ISO-8859-1 Code (markup): Is there something wrong with my apache config? You can reproduce this with these two test urls: http://www.plantacious.com/garden/main.pl?a=getPicture&pic_key=5 http://www.plantacious.com/garden/main.pl?a=getPicture&pic_key=6 The first is a jpg, the second is a png The second problem is I occasionally get Firebug telling me I have a 500 Internal Server Error, but then the page renders fine and there isn't anything in the error_logs. This is what I see when I use Wireshark to monitor the session: HTTP/1.1 500 Internal Server Error Date: Fri, 22 Jan 2010 20:50:55 GMT Server: Apache Set-Cookie: email=-redacted-; path=/; expires=Sat, 22-Jan-2011 20:50:55 GMT Set-Cookie: password1=-redacted-; path=/; expires=Sat, 22-Jan-2011 20:50:55 GMT Keep-Alive: timeout=2, max=100 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html; charset=ISO-8859-1 Code (markup): Anyone have any ideas on how I can troubleshoot these issues? Thanks!