< Summary

Information
Class: Elsa.Http.Services.DefaultAbsoluteUrlProvider
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/DefaultAbsoluteUrlProvider.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 33
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
ToAbsoluteUrl(...)0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/DefaultAbsoluteUrlProvider.cs

#LineLine coverage
 1using Elsa.Http.Options;
 2using Microsoft.Extensions.Options;
 3
 4namespace Elsa.Http.Services;
 5
 6/// <inheritdoc />
 7public class DefaultAbsoluteUrlProvider : IAbsoluteUrlProvider
 8{
 9    private readonly IOptions<HttpActivityOptions> _options;
 10
 11    /// <summary>
 12    /// Initializes a new instance of the <see cref="DefaultAbsoluteUrlProvider"/> class.
 13    /// </summary>
 014    public DefaultAbsoluteUrlProvider(IOptions<HttpActivityOptions> options) => _options = options;
 15
 16    /// <inheritdoc />
 17    public Uri ToAbsoluteUrl(string relativePath)
 18    {
 019        var baseUrl = _options.Value.BaseUrl;
 20
 021        if (baseUrl == null)
 022            throw new Exception(
 023                "There was no base URL configured, which means no absolute URL can be generated from outside the context
 24
 25        // To not lose any base path information, we need to ensure that:
 26        // - Base path ends with a slash.
 27        // - Relative path does NOT start with a slash.
 028        var baseUri = new Uri(baseUrl.ToString().TrimEnd('/') + '/');
 029        relativePath = relativePath.TrimStart('/');
 30
 031        return new Uri(baseUri, relativePath);
 32    }
 33}