[interchange-cvs] interchange - heins modified 2 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Sat Jul 26 17:25:00 EDT 2003


User:      heins
Date:      2003-07-26 20:25:44 GMT
Modified:  lib/Vend Config.pm Dispatch.pm
Log:
* Add DeliverImage directive that enables fast IC delivery of
  images requested from it.

  To enable, do in catalog.cfg:

  	DeliverImage  Yes

  If the file extension is present and the MimeType for that extension
  begins with "image/", the path will be adjusted to add ImageDir
  or ImageDirSecure, and a 302 issued.

  This happens before database or session opens, and is quite fast.

  Sets $Vend::tmp_session so no cookie is issued.

* TODO: Add processing routine or option to deliver different path
  from ImageSecure, possibly for at DBI-based image CGI.

Revision  Changes    Path
2.123     +3 -2      interchange/lib/Vend/Config.pm


rev 2.123, prev_rev 2.122
Index: Config.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Config.pm,v
retrieving revision 2.122
retrieving revision 2.123
diff -u -r2.122 -r2.123
--- Config.pm	21 Jul 2003 17:44:03 -0000	2.122
+++ Config.pm	26 Jul 2003 20:25:43 -0000	2.123
@@ -1,6 +1,6 @@
 # Vend::Config - Configure Interchange
 #
-# $Id: Config.pm,v 2.122 2003/07/21 17:44:03 mheins Exp $
+# $Id: Config.pm,v 2.123 2003/07/26 20:25:43 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -48,7 +48,7 @@
 use Vend::File;
 use Vend::Data;
 
-$VERSION = substr(q$Revision: 2.122 $, 10);
+$VERSION = substr(q$Revision: 2.123 $, 10);
 
 my %CDname;
 my %CPname;
@@ -454,6 +454,7 @@
 	['ImageDirSecure',   undef,     	     ''],
 	['ImageDirInternal', undef,     	     ''],
 	['ImageDir',	 	 undef,     	     ''],
+	['DeliverImage',     'yesno',			 'no'],
 	['UseCode',		 	 undef,     	     'yes'],
 	['SetGroup',		 'valid_group',      ''],
 	['UseModifier',		 'array',     	     ''],



1.25      +30 -4     interchange/lib/Vend/Dispatch.pm


rev 1.25, prev_rev 1.24
Index: Dispatch.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Dispatch.pm,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Dispatch.pm	11 Jul 2003 15:27:41 -0000	1.24
+++ Dispatch.pm	26 Jul 2003 20:25:43 -0000	1.25
@@ -1,6 +1,6 @@
 # Vend::Dispatch - Handle Interchange page requests
 #
-# $Id: Dispatch.pm,v 1.24 2003/07/11 15:27:41 racke Exp $
+# $Id: Dispatch.pm,v 1.25 2003/07/26 20:25:43 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 2002 Mike Heins <mike at perusion.net>
@@ -26,7 +26,7 @@
 package Vend::Dispatch;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 1.24 $, 10);
+$VERSION = substr(q$Revision: 1.25 $, 10);
 
 use POSIX qw(strftime);
 use Vend::Util;
@@ -967,9 +967,32 @@
 					if defined $Vend::Cfg->{Locale_repository}{$loc};
 		}
 	}
+
 	$::Variable = $Vend::Cfg->{Variable};
 	$::Pragma   = { %{ $Vend::Cfg->{Pragma} } };
 
+	my $mt;
+	if($Vend::Cfg->{DeliverImage}
+		and $CGI::request_method eq 'GET'
+		and $CGI::path_info =~ /\.(\w+)$/
+		and $mt = Vend::Util::mime_type($CGI::path_info)
+		and $mt =~ m{^image/}
+	  )
+	{
+
+#::logDebug("deliver image: method=$CGI::request_method type=$mt");
+		my $imgdir = $Vend::Cfg->{ImageDir};
+		my $fn = $CGI::path_info;
+		$fn =~ s:^/+::;
+		if($CGI::secure) {
+			 $imgdir = $Vend::Cfg->{ImageDirSecure}
+				if $Vend::Cfg->{ImageDirSecure};
+		}
+		$Vend::tmp_session = 1;
+		Vend::Tags->deliver($mt, { location => "$imgdir$fn" } );
+		return;
+	}
+
 	if (defined $Global::SelectorAlias{$CGI::script_name}
 		and ! defined $Vend::InternalHTTP                 )
 	{
@@ -1021,6 +1044,7 @@
 #show_times("end cgi and config mapping") if $Global::ShowTimes;
 	open_database();
 #show_times("end open_database") if $Global::ShowTimes;
+	return 1;
 }
 
 sub close_cat {
@@ -1069,7 +1093,8 @@
 
 	adjust_cgi();
 
-	open_cat();
+	## If returns false then was a 404 no catalog or a delivered image
+	open_cat() or return 1;
 
 	$CGI::user = Vend::Util::check_authorization($CGI::authorization)
 		if defined $CGI::authorization;
@@ -1378,7 +1403,8 @@
     }
 
 	$Vend::FinalPath =~ s:^/+::;
-	$Vend::FinalPath =~ s/(\.html?)$//;
+	$Vend::FinalPath =~ s/(\.html?)$//
+		and $Vend::Extension = $1;
 
 	my $record;
 	my $adb;







More information about the interchange-cvs mailing list