Example #1
0
        private async Task <IActionResult> ServeProxyFile(string package, ProxyFile proxyFile, Assembly assembly, string buildHash)
        {
            string proxy;

            switch (proxyFile)
            {
            case ProxyFile.JavaScript:
                proxy = await _proxies.GenerateJavaScriptProxy(package, CancellationToken);

                break;

            case ProxyFile.TypeScript:
                proxy = await _proxies.GenerateTypeScriptProxy(package, CancellationToken);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(proxyFile), proxyFile, null);
            }

            Response.Headers.Add(HeaderNames.ETag, assembly.ComputePackageHash(buildHash));
            Response.Headers.Add(HeaderNames.CacheControl, "public,max-age=31536000");
            switch (proxyFile)
            {
            case ProxyFile.JavaScript:
                return(File(Encoding.UTF8.GetBytes(proxy), "application/javascript"));

            case ProxyFile.TypeScript:
                return(File(Encoding.UTF8.GetBytes(proxy), "application/typescript"));

            default:
                throw new ArgumentOutOfRangeException(nameof(proxyFile), proxyFile, null);
            }
        }