Exemple #1
0
        /// <summary>
        /// Matches a request by HTTP header. A type converter is used to convert the <paramref name="value"/> to string.
        /// </summary>
        /// <param name="builder">The request matching builder instance.</param>
        /// <param name="name">The header name.</param>
        /// <param name="value">The header value.</param>
        /// <returns>The request matching builder instance.</returns>
        public static RequestMatching Header <T>(this RequestMatching builder, string name, T value)
            where T : struct
        {
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));

            return(builder.Header(name, converter.ConvertToString(value)));
        }
        /// <summary>
        /// Matches a request when it has an Authorization header with specified bearer <paramref name="token"/>.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="token">The bearer token (without 'Bearer').</param>
        /// <returns></returns>
        public static RequestMatching BearerToken(this RequestMatching builder, string token)
        {
            if (token is null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            return(builder.Header("Authorization", $"Bearer {token}"));
        }
Exemple #3
0
        /// <summary>
        /// Matches a request by HTTP header on a datetime value (per RFC-2616).
        /// </summary>
        /// <param name="builder">The request matching builder instance.</param>
        /// <param name="name">The header name.</param>
        /// <param name="date">The header value.</param>
        /// <returns>The request matching builder instance.</returns>
        public static RequestMatching Header(this RequestMatching builder, string name, DateTimeOffset date)
        {
            // https://tools.ietf.org/html/rfc2616#section-3.3.1
            CultureInfo ci = CultureInfo.InvariantCulture;

#if NETFRAMEWORK
            // .NET Framework does not normalize other common date formats,
            // so we use multiple matches.
            return(builder.Any(any => any
                               .Header(name, date.ToString("R", ci))
                               .Header(name, date.ToString("dddd, dd-MMM-yy HH:mm:ss 'GMT'", ci))       // RFC 1036
                               .Header(name, date.ToString("ddd MMM  d  H:mm:ss yyyy", ci))             // ANSI C's asctime()
                               ));
#else
            return(builder.Header(name, date.ToString("R", ci)));
#endif
        }
Exemple #4
0
 public static RequestMatching Headers(this RequestMatching builder, string name, params string[] values)
 {
     return(builder.Header(name, values));
 }
Exemple #5
0
 /// <summary>
 /// Matches a request by HTTP header on a datetime value (per RFC-2616).
 /// </summary>
 /// <param name="builder">The request matching builder instance.</param>
 /// <param name="name">The header name.</param>
 /// <param name="date">The header value.</param>
 /// <returns>The request matching builder instance.</returns>
 public static RequestMatching Header(this RequestMatching builder, string name, DateTime date)
 {
     return(builder.Header(name, (DateTimeOffset)date.ToUniversalTime()));
 }
 /// <summary>
 /// Matches a request when it has an Authorization header with a bearer token.
 /// </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static RequestMatching BearerToken(this RequestMatching builder)
 {
     return(builder.Header("Authorization", "Bearer *", true));
 }