Skip to content

Bypass or deactivate i18n response filter once installed #333

@macote

Description

@macote

I'm using i18n with OWIN middleware and it is configured with i18n.UrlLocalizationScheme set to Void.

I'm having an issue in some cases where specific controller actions are used to download binaries. For those cases, I'm faced with two possibilities:

  • add the controller action path component URL to the UrlsToExcludeFromProcessing regex
  • remove the response filter while handling the request in the controller action

The problem with the UrlsToExcludeFromProcessing solution is that there are multiple controller actions and it is not simple to manage. Also, the need to exclude a specific action path URL could be conditionaly based on some logic determined inside the controller action.

It is quite easy to remove the response filter by setting the Response.Filter to null inside a controller action and this is what I'm doing currently:

    if (this.HttpContext.Response.Filter is i18n.ResponseFilter)
    {
        // Remove i18n filter since a file doesn't need to be translated.
        this.HttpContext.Response.Filter = null;
    }

Unfortunately, the i18n response filter might be wrapped by another filter at that point. In that case, it is not possible to determine if a i18n filter is installed.

Is there something I missed that I could do besides those two possibilities? If not, I propose to add some code to i18n to allow bypassing or deactivating the i18n filter. One way to accomplish this would be to add a 'Bypass' property to the ResponseFilter class and store a reference of the filter somewhere like for example the OWIN context. If 'Bypass' is true, use a logic similar to the one used when a stream is compressed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions