<commit_before>namespace Nancy.Routing
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// Default route invoker implementation-
    /// </summary>
    public class DefaultRouteInvoker : IRouteInvoker
    {
        private readonly IEnumerable<ISerializer> serializers;

        public DefaultRouteInvoker(IEnumerable<ISerializer> serializers)
        {
            this.serializers = serializers;
        }

        /// <summary>
        /// Invokes the specified <paramref name="route"/> with the provided <paramref name="parameters"/>.
        /// </summary>
        /// <param name="route">The route that should be invoked.</param>
        /// <param name="parameters">The parameters that the route should be invoked with.</param>
        /// <param name="context">The context of the route that is being invoked.</param>
        /// <returns>A <see cref="Response"/> intance that represents the result of the invoked route.</returns>
        public Response Invoke(Route route, DynamicDictionary parameters, NancyContext context)
        {
            var result =
                route.Invoke(parameters);

            var response =
                CastResultToResponse(result) ?? GetNegotiatedResponse(result, context);

            return response;
        }

        private static Response CastResultToResponse(dynamic result)
        {
            return result as Response;
        }

        private Response GetNegotiatedResponse(dynamic result, NancyContext context)
        {
            var headers =
                context.Request.Headers;

            var valid =
                from accept in headers.Accept
                let s = this.serializers.FirstOrDefault(s => s.CanSerialize(accept.Item1))
                where s != null
                select Tuple.Create(accept.Item1, s);

            var serializer =
                valid.FirstOrDefault();

            var response = new Response {
                ContentType = serializer.Item1,
                StatusCode = HttpStatusCode.OK,
                Contents = s => serializer.Item2.Serialize(serializer.Item1, result, s)
            };

            if (valid.Count() > 0)
            {
                response.WithHeader("Vary", "Accept");
            }

            return response;
        }
    }
}<commit_msg>Only add Vary header if there is more than one serializer<commit_after>namespace Nancy.Routing
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// Default route invoker implementation-
    /// </summary>
    public class DefaultRouteInvoker : IRouteInvoker
    {
        private readonly IEnumerable<ISerializer> serializers;

        public DefaultRouteInvoker(IEnumerable<ISerializer> serializers)
        {
            this.serializers = serializers;
        }

        /// <summary>
        /// Invokes the specified <paramref name="route"/> with the provided <paramref name="parameters"/>.
        /// </summary>
        /// <param name="route">The route that should be invoked.</param>
        /// <param name="parameters">The parameters that the route should be invoked with.</param>
        /// <param name="context">The context of the route that is being invoked.</param>
        /// <returns>A <see cref="Response"/> intance that represents the result of the invoked route.</returns>
        public Response Invoke(Route route, DynamicDictionary parameters, NancyContext context)
        {
            var result =
                route.Invoke(parameters);

            var response =
                CastResultToResponse(result) ?? GetNegotiatedResponse(result, context);

            return response;
        }

        private static Response CastResultToResponse(dynamic result)
        {
            return result as Response;
        }

        private Response GetNegotiatedResponse(dynamic result, NancyContext context)
        {
            var headers =
                context.Request.Headers;

            var valid =
                from accept in headers.Accept
                let s = this.serializers.FirstOrDefault(s => s.CanSerialize(accept.Item1))
                where s != null
                select Tuple.Create(accept.Item1, s);

            var serializer =
                valid.FirstOrDefault();

            var response = new Response {
                ContentType = serializer.Item1,
                StatusCode = HttpStatusCode.OK,
                Contents = s => serializer.Item2.Serialize(serializer.Item1, result, s)
            };

            if (valid.Count() > 1)
            {
                response.WithHeader("Vary", "Accept");
            }

            return response;
        }
    }
}
{'fraction_non_alphanumeric': 0.08960720130932896, 'fraction_numerical': 0.0024549918166939444, 'mean_word_length': 1.6996134732192159, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2221248', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1109, 'n_words': 316}