[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

mod_mime passthrough for svn repository resources

From: dorian taylor <dorian_at_foobarsystems.com>
Date: 2004-08-12 19:30:17 CEST

hello all,

with my particular application of subversion, i find it advantageous
to have the mime types of the resources divined by apache, should
they not be explicitly set by svn:mime-type. however, mod_mime
returns DECLINED unless there is an r->filename present. the technique
i used was to first modify mod_dav_svn's repos.c, then create a
mod_perl header parser handler to supplant the bogus filename. the
filename can be anything, as long as it ends with the name of the
resource, as mod_mime does on actual operations on any files, but
simply parses the extensions out of the name. now, there are security
implications of passing in a path that stands the chance of actually
existing elsewhere on the filesystem, so i took the original value
(at this stage, the value of the <Location> block from which the
dav module was invoked) and concatenated it to r->uri with a !, as
i've seen occur elsewhere in svn code.

the only caveat i can see would revolve around other handlers relying
on the contents of r->filename between the header parser and content
phases (e.g. mod_negotiation and MultiViews, as i found when i first
set this up). unless it is a cardinal no-no to either a) have
subversion implicitly supply correct mime-type information for
non-collection resources or b) set a bogus r->filename in a handler,
i'd be inclined to redo the header parser in c and submit a patch




the minor patch to repos.c:

--- subversion/mod_dav_svn/repos.c.orig Wed Aug 11 14:25:30 2004
+++ subversion/mod_dav_svn/repos.c Wed Aug 11 14:56:54 2004
@@ -1866,7 +1866,11 @@
                                    "could not fetch the resource's MIME type",
- mimetype = value ? value->data : "text/plain";
+ /* if we do not have an svn:mime-type, only set text/plain
+ if there isn't already something in the header */
+ mimetype = value ? value->data :
+ (r->content_type ? r->content_type : "text/plain");
       serr = svn_mime_type_validate (mimetype, resource->pool);
       if (serr)


the q&d mod_perl module:


package MyApache::SVN::HeaderParser;

use 5.008;
use strict;
use warnings;

use Apache::RequestRec ();
use Apache::RequestUtil ();
use Apache::Log ();
use Apache::Const -compile => qw(OK DECLINED);
use APR::Table ();

our @ISA = qw();

our $VERSION = '0.01';

sub handler {
  my $r = shift;
  return Apache::DECLINED if ($r->notes->get(__PACKAGE__ . '::seen'));
  $r->log->debug(sprintf('before: %s', $r->filename));
  $r->filename(sprintf('%s/!%s', $r->filename , $r->uri));
  $r->log->debug(sprintf('after: %s', $r->filename));
  $r->notes->set(__PACKAGE__ . '::seen', 1);
  return Apache::OK;


To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Aug 12 19:30:33 2004

This is an archived mail posted to the Subversion Dev mailing list.