Example #1
0
            public override bool CanExecute(AceeptHeaderEnricherContext context)
            {
                if (string.IsNullOrEmpty(context.FormatFromQuery))
                {
                    return(false);
                }


                return(true);
            }
Example #2
0
            public override bool CanExecute(AceeptHeaderEnricherContext context)
            {
                if (context.Accept == null || context.Accept.Any(a => string.IsNullOrEmpty(a.Charset) == false) == false)
                {
                    return(false);
                }

                if (context.AcceptCharset != null && context.AcceptCharset.Any())
                {
                    return(false);
                }

                return(true);
            }
Example #3
0
            public override bool CanExecute(AceeptHeaderEnricherContext context)
            {
                if (context.Accept == null || context.Accept.Any() == false)
                {
                    return(false);
                }

                //Если есть формат с Url то Accept устанавливать не нужно
                if (string.IsNullOrEmpty(context.FormatFromQuery) == false)
                {
                    return(false);
                }

                return(true);
            }
Example #4
0
        public async Task Invoke(HttpContext context)
        {
            var aceeptHeaderEnricherContext = new AceeptHeaderEnricherContext(context, _options);

            foreach (var aceeptHeaderEnricher in _aceeptHeaderEnrichers.Where(a =>
                                                                              a.CanExecute(aceeptHeaderEnricherContext)))
            {
                aceeptHeaderEnricher.Execute(aceeptHeaderEnricherContext);
            }


            var acceptHeaders = new List <MediaTypeSegmentWithQuality>();

            AcceptHeaderParser.ParseAcceptHeader(context.Request.Headers[HeaderNames.Accept], acceptHeaders);
            context.Features.Set <IOutputFormatter>(OutputFormatterSelector.SelectFormatter(_options.Value.OutputFormatters.OfType <TextOutputFormatter>(), acceptHeaders));


            await _next(context);
        }
Example #5
0
            public override bool CanExecute(AceeptHeaderEnricherContext context)
            {
                if (string.IsNullOrEmpty(context.ContentType?.Charset))
                {
                    return(false);
                }


                if (context.Accept != null && context.Accept.Any(a => string.IsNullOrEmpty(a.Charset) == false))
                {
                    return(false);
                }

                //Если установлен AcceptCharset  из ContentType устанавливать не нужно
                if (context.AcceptCharset != null && context.AcceptCharset.Any())
                {
                    return(false);
                }


                return(true);
            }
Example #6
0
 public override void Execute(AceeptHeaderEnricherContext context)
 {
     context.Context.Request.Headers.Remove(HeaderNames.Accept);
     context.Context.Request.Headers.Append(HeaderNames.Accept, context.FormatFromQuery);
 }
Example #7
0
 public override void Execute(AceeptHeaderEnricherContext context)
 {
     context.Context.Request.Headers.Append(HeaderNames.AcceptCharset,
                                            string.Join(",", context.Accept.Select(a => $"{a.Charset}{BuildQualityString(a)}")));
 }
Example #8
0
 public override void Execute(AceeptHeaderEnricherContext context)
 {
     context.Context.Request.Headers.Append(HeaderNames.AcceptCharset,
                                            $"{context.ContentType.Charset}{BuildQualityString(context.ContentType)}");
 }
Example #9
0
 public abstract void Execute(AceeptHeaderEnricherContext context);
Example #10
0
 public abstract bool CanExecute(AceeptHeaderEnricherContext context);