< Summary

Information
Class: IceRpc.RequestContext.RequestContextMiddleware
Assembly: IceRpc.RequestContext
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.RequestContext/RequestContextMiddleware.cs
Tag: 1321_24790053727
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 44
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
DispatchAsync(...)100%66100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.RequestContext/RequestContextMiddleware.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Features;
 4using IceRpc.Ice.Codec;
 5using System.Buffers;
 6using ZeroC.Slice.Codec;
 7
 8namespace IceRpc.RequestContext;
 9
 10/// <summary>Represents a middleware that decodes request context fields into request context features.</summary>
 11/// <remarks>Both the ice protocol and the icerpc protocol can transmit request context fields with requests; while
 12/// icerpc can transmit all request fields, ice can only transmit request context fields and idempotent fields.
 13/// </remarks>
 14public class RequestContextMiddleware : IDispatcher
 15{
 16    private readonly IDispatcher _next;
 17
 18    /// <summary>Constructs a request context middleware.</summary>
 19    /// <param name="next">The next dispatcher in the dispatch pipeline.</param>
 2220    public RequestContextMiddleware(IDispatcher next) => _next = next;
 21
 22    /// <inheritdoc/>
 23    public ValueTask<OutgoingResponse> DispatchAsync(IncomingRequest request, CancellationToken cancellationToken)
 8724    {
 25        // Decode Context from Fields and set corresponding feature.
 8726        if (request.Fields.TryGetValue(RequestFieldKey.Context, out ReadOnlySequence<byte> value))
 1527        {
 1528            Dictionary<string, string> context = request.Protocol == Protocol.Ice ?
 729                value.DecodeIceBuffer((ref IceDecoder decoder) => decoder.DecodeDictionary(
 730                    size => new Dictionary<string, string>(size),
 731                    keyDecodeFunc: (ref IceDecoder decoder) => decoder.DecodeString(),
 1432                    valueDecodeFunc: (ref IceDecoder decoder) => decoder.DecodeString())) :
 2333                value.DecodeSliceBuffer((ref SliceDecoder decoder) => decoder.DecodeDictionary(
 834                    size => new Dictionary<string, string>(size),
 835                    keyDecodeFunc: (ref SliceDecoder decoder) => decoder.DecodeString(),
 3136                    valueDecodeFunc: (ref SliceDecoder decoder) => decoder.DecodeString()));
 1337            if (context.Count > 0)
 1338            {
 1339                request.Features = request.Features.With<IRequestContextFeature>(new RequestContextFeature(context));
 1340            }
 1341        }
 8542        return _next.DispatchAsync(request, cancellationToken);
 8543    }
 44}