Bill Hertzing
Bill Hertzing

Reputation: 75

ServiceStack Plugin How to add MimeType for new file suffix, and allow the file suffix to be served?

I would like to add the file suffix ".wasm" to the AllowFileExtensions property of the AppHost, and I'd like to associate the MimeType "application/wasm" to that file suffix, so that a Windows service based on ServiceStack can serve static files with this suffix. In my plugin's Configure method, I've tried this code, but it is not working.

public void Configure(IAppHost appHost) {
  // Add the MIMEType application/wasm and associate it with .wasm files
  MimeTypes.ExtensionMimeTypes["wasm"] = "application/wasm";
  // Allow static files ending in .wasm to be served
  var config = new HostConfig();
  var allowFileExtensions = config.AllowFileExtensions;
  allowFileExtensions.Add(".wasm");
}

Requests to my ServiceStack Windows service for static files ending in .wasm return a 403 error, and the Content-Type in the response headers is "text/plain".

Any suggestions on what I'm doing wrong, and how best to allow the new suffix and associate the new MimeType?

Upvotes: 1

Views: 127

Answers (1)

mythz
mythz

Reputation: 143339

I've added wasm file extensions to ServiceStack's allowed File Extensions list in this commit. This change is available from v5.1.1 that's now available on MyGet.

For earlier versions of ServiceStack you can register an allowed File Extension by modifying IAppHost.Config, e.g:

public void Register(IAppHost appHost) 
{
    appHost.Config.AllowFileExtensions.Add("wasm");
}

You don't need to register a MimeType for wasm as the default MimeType for unknown Content-Types is application/{ext} which for .wasm returns application/wasm.

Upvotes: 2

Related Questions