Skip to content

Support mapping extension-less files mimetype in FileExtensionContentTypeProvider #66495

@fredericDelaporte

Description

@fredericDelaporte

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Some vendors mandate the hosting of extension-less static files for the use of their services, such as Apple with their .well-known/apple-developer-merchantid-domain-association or .well-known/apple-app-site-association files.

As far as I know, this is currently doable with .net only by enabling the ServeUnknownFileTypes option from StaticFileOptions, which is a lot "wider" than the need and is a bigger security risk than enabling an extension-less file mapping.

Describe the solution you'd like

The FileExtensionContentTypeProvider alreayd accepts en empty extension mapping, like this:

var provider = new FileExtensionContentTypeProvider();
provider.Mappings[""] = "text/plain";

But its implementation short-circuit on extension-less path, causing the declaration to be useless.
Its GetExtension method yields null in such case, which causes the middleware to not try to lookup its extension table.

int index = path.LastIndexOf('.');
if (index < 0)
{
return null;
}

If it were to yield the empty string in such case instead, it should allow to map extension-less files.

Additional context

Currently we use this workaround:

app.UseStaticFiles(
    new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", ".well-known")),
        RequestPath = "/.well-known",
        ServeUnknownFileTypes = true,
        DefaultContentType = "text/plain"
    });

We would rather use:

var provider = new FileExtensionContentTypeProvider();
provider.Mappings[""] = "text/plain";
app.UseStaticFiles(
    new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", ".well-known")),
        RequestPath = "/.well-known",
        ContentTypeProvider = provider
    });

By the way, that is still not "good" as we wish. When served through IIS static file handler, we restrict it further to only the file path. But that does not seem doable with the .net API as currently is.
Example through IIS:

<location path=".well-known/apple-developer-merchantid-domain-association">
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension="." mimeType="text/plain" />
  </system.webServer>
</location>

And in case we needed to host an .well-known/apple-app-site-association file too, we would be stuck not being able to specify two different mime types for these two extension-less files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions