• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ThreeMammals / Ocelot / 23302213965

19 Mar 2026 03:19PM UTC coverage: 91.219% (-1.3%) from 92.49%
23302213965

Pull #2369

github

web-flow
Merge 7f6f01146 into 086c7b15c
Pull Request #2369: Pre-Release 25.0 aka Beta 2

8404 of 9213 relevant lines covered (91.22%)

2131.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
src/Ocelot/Infrastructure/RequestData/HttpDataRepository.cs
1
using Microsoft.AspNetCore.Http;
2
using Ocelot.Responses;
3

4
namespace Ocelot.Infrastructure.RequestData;
5

6
public class HttpDataRepository : IRequestScopedDataRepository
7
{
8
    private readonly IHttpContextAccessor _contextAccessor;
9

10
    public HttpDataRepository(IHttpContextAccessor contextAccessor)
20✔
11
    {
20✔
12
        _contextAccessor = contextAccessor;
20✔
13
    }
20✔
14

15
    public Response Add<T>(string key, T value)
16
    {
1✔
17
        try
18
        {
1✔
19
            _contextAccessor.HttpContext.Items.Add(key, value);
1✔
20
            return new OkResponse();
1✔
21
        }
22
        catch (Exception exception)
×
23
        {
×
24
            return new ErrorResponse(new CannotAddDataError(string.Format($"Unable to add data for key: {key}, exception: {exception.Message}")));
×
25
        }
26
    }
1✔
27

28
    public Response Update<T>(string key, T value)
29
    {
1✔
30
        try
31
        {
1✔
32
            _contextAccessor.HttpContext.Items[key] = value;
1✔
33
            return new OkResponse();
1✔
34
        }
35
        catch (Exception exception)
×
36
        {
×
37
            return new ErrorResponse(new CannotAddDataError(string.Format($"Unable to update data for key: {key}, exception: {exception.Message}")));
×
38
        }
39
    }
1✔
40

41
    public Response<T> Get<T>(string key)
42
    {
4✔
43
        if (_contextAccessor?.HttpContext?.Items == null)
4✔
44
        {
×
45
            return new ErrorResponse<T>(new CannotFindDataError($"Unable to find data for key: {key} because HttpContext or HttpContext.Items is null"));
×
46
        }
47

48
        return _contextAccessor.HttpContext.Items.TryGetValue(key, out var item)
4✔
49
            ? new OkResponse<T>((T)item)
4✔
50
            : new ErrorResponse<T>(new CannotFindDataError($"Unable to find data for key: {key}"));
4✔
51
    }
4✔
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc