|
3 | 3 |
|
4 | 4 | using System.Diagnostics; |
5 | 5 | using System.Linq; |
| 6 | +using System.Reflection.PortableExecutable; |
6 | 7 | using System.Runtime.InteropServices; |
7 | 8 | using System.Text; |
8 | 9 | using System.Text.Encodings.Web; |
@@ -321,70 +322,10 @@ private void WriteComponentHtml(int componentId, TextWriter output, bool allowBo |
321 | 322 |
|
322 | 323 | private void AppendWebAssemblyPreloadHeaders() |
323 | 324 | { |
324 | | - var assets = _httpContext.GetEndpoint()?.Metadata.GetMetadata<ResourceAssetCollection>(); |
325 | | - if (assets != null) |
| 325 | + var preloads = _httpContext.GetEndpoint()?.Metadata.GetMetadata<ResourcePreloadCollection>(); |
| 326 | + if (preloads != null && preloads.TryGetLinkHeaders("webassembly", out var linkHeaders)) |
326 | 327 | { |
327 | | - var headers = new List<(string? Order, string Value)>(); |
328 | | - foreach (var asset in assets) |
329 | | - { |
330 | | - if (asset.Properties == null) |
331 | | - { |
332 | | - continue; |
333 | | - } |
334 | | - |
335 | | - // Use preloadgroup=webassembly to identify assets that should to be preloaded |
336 | | - string? header = null; |
337 | | - foreach (var property in asset.Properties) |
338 | | - { |
339 | | - if (property.Name.Equals("preloadgroup", StringComparison.OrdinalIgnoreCase) && property.Value.Equals("webassembly", StringComparison.OrdinalIgnoreCase)) |
340 | | - { |
341 | | - header = $"<{asset.Url}>"; |
342 | | - break; |
343 | | - } |
344 | | - } |
345 | | - |
346 | | - if (header == null) |
347 | | - { |
348 | | - continue; |
349 | | - } |
350 | | - |
351 | | - string? order = null; |
352 | | - foreach (var property in asset.Properties) |
353 | | - { |
354 | | - if (property.Name.Equals("preloadrel", StringComparison.OrdinalIgnoreCase)) |
355 | | - { |
356 | | - header = String.Concat(header, "; rel=", property.Value); |
357 | | - } |
358 | | - else if (property.Name.Equals("preloadas", StringComparison.OrdinalIgnoreCase)) |
359 | | - { |
360 | | - header = String.Concat(header, "; as=", property.Value); |
361 | | - } |
362 | | - else if (property.Name.Equals("preloadpriority", StringComparison.OrdinalIgnoreCase)) |
363 | | - { |
364 | | - header = String.Concat(header, "; fetchpriority=", property.Value); |
365 | | - } |
366 | | - else if (property.Name.Equals("preloadcrossorigin", StringComparison.OrdinalIgnoreCase)) |
367 | | - { |
368 | | - header = String.Concat(header, "; crossorigin=", property.Value); |
369 | | - } |
370 | | - else if (property.Name.Equals("integrity", StringComparison.OrdinalIgnoreCase)) |
371 | | - { |
372 | | - header = String.Concat(header, "; integrity=\"", property.Value, "\""); |
373 | | - } |
374 | | - else if (property.Name.Equals("preloadorder", StringComparison.OrdinalIgnoreCase)) |
375 | | - { |
376 | | - order = property.Value; |
377 | | - } |
378 | | - } |
379 | | - |
380 | | - if (header != null) |
381 | | - { |
382 | | - headers.Add((order, header)); |
383 | | - } |
384 | | - } |
385 | | - |
386 | | - headers.Sort((a, b) => string.Compare(a.Order, b.Order, StringComparison.InvariantCulture)); |
387 | | - _httpContext.Response.Headers.Link = StringValues.Concat(_httpContext.Response.Headers.Link, headers.Select(h => h.Value).ToArray()); |
| 328 | + _httpContext.Response.Headers.Link = StringValues.Concat(_httpContext.Response.Headers.Link, linkHeaders); |
388 | 329 | } |
389 | 330 | } |
390 | 331 |
|
|
0 commit comments