public static void SerializeCookieInfo(IRequestCookieCollection cookies, IgnorePropertiesInfo ignoreInfo, ILogger logger) { if (cookies != null && cookies.Count != 0) { try { logger.BeginWriteObject("cookie"); foreach (string key in cookies.Keys) { string cookie = cookies[key]; logger.BeginWriteObject(key); //logger.WriteValue("domain", cookie.Domain); //logger.WriteValue("expires", cookie.Expires.ToString()); logger.WriteValue("name", key); //logger.WriteValue("secure", cookie.Secure); //logger.WriteValue("value", cookie.Value); if (ignoreInfo != null && ignoreInfo.ShouldIgnore(key)) { logger.WriteValue("value", RequestBodyFilter.ValueStripped); } else { logger.WriteValue("value", cookie); } logger.EndWriteObject(key); } } finally { logger.EndWriteObject("cookie"); } } }
public ResponseCollector(HttpResponse response, string name, IgnorePropertiesInfoConfig ignoreConfig) { this.response = response; this.name = name; this.ignoreHeaders = IgnorePropertiesInfo.FromString(ignoreConfig.IgnoreHeaders); //this.ignoreCookies = IgnorePropertiesInfo.FromString(ignoreConfig.IgnoreCookies); }
public RequestCollector(HttpRequest request, string name, IgnorePropertiesInfoConfig ignoreConfig) { this.request = request; this.name = name; this.ignoreFormFields = IgnorePropertiesInfo.FromString(ignoreConfig.IgnoreFormFields); this.ignoreHeaders = IgnorePropertiesInfo.FromString(ignoreConfig.IgnoreHeaders); this.ignoreCookies = IgnorePropertiesInfo.FromString(ignoreConfig.IgnoreCookies); this.ignoreServerVariables = IgnorePropertiesInfo.FromString(ignoreConfig.IgnoreServerVariables); this.ignoreRequestBody = ignoreConfig.IgnoreRequestBody; }
public static IgnorePropertiesInfo FromString(string value) { IgnorePropertiesInfo result = new IgnorePropertiesInfo(); result.IgnoreNamesExact = new HashSet <string>(StringComparer.OrdinalIgnoreCase); result.IgnoreNamesStartsWith = new List <string>(); result.IgnoreNamesEndsWith = new List <string>(); result.IgnoreNamesContains = new List <string>(); try { if (String.IsNullOrEmpty(value)) { return(result); } string[] names = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (names == null || names.Length <= 0) { return(result); } int count = names.Length; for (int i = 0; i < count; i++) { string item = names[i].Trim(); if (!String.IsNullOrEmpty(item)) { if (item == "*") { result.IgnoreAll = true; break; } bool endsWith = item.StartsWith("*"); bool startsWith = item.EndsWith("*"); if (startsWith && endsWith) { result.IgnoreNamesContains.Add(item.Trim('*')); } else if (startsWith && !endsWith) { result.IgnoreNamesStartsWith.Add(item.Trim('*')); } else if (!startsWith && endsWith) { result.IgnoreNamesEndsWith.Add(item.Trim('*')); } else { if (!result.IgnoreNamesExact.Contains(item)) { result.IgnoreNamesExact.Add(item); } } } } return(result); } catch { return(result); } }
static Dictionary <string, string> SerializeInfoCore(IEnumerable <KeyValuePair <string, StringValues> > info, string name, IgnorePropertiesInfo ignoreInfo, ILogger logger) { if (info == null) { return(null); } Dictionary <string, string> result = null; int written = 0; try { foreach (KeyValuePair <string, StringValues> pair in info) { if (written == 0) { logger.BeginWriteObject(name); } written++; if (ignoreInfo != null && ignoreInfo.ShouldIgnore(pair.Key)) { if (result == null) { result = new Dictionary <string, string>(); } result[pair.Key] = pair.Value.ToString(); logger.WriteValue(pair.Key, RequestBodyFilter.ValueStripped); } else { logger.WriteValue(pair.Key, pair.Value.ToString()); } } } finally { if (written > 0) { logger.EndWriteObject(name); } } return(result); }
public static void SerializeInfo(IQueryCollection query, string name, IgnorePropertiesInfo ignoreInfo, ILogger logger) { SerializeInfoCore(query, name, ignoreInfo, logger); }
public static void SerializeInfo(IHeaderDictionary headers, string name, IgnorePropertiesInfo ignoreInfo, ILogger logger) { SerializeInfoCore(headers, name, ignoreInfo, logger); }
public static Dictionary <string, string> SerializeInfo(IFormCollection info, string name, IgnorePropertiesInfo ignoreInfo, ILogger logger) { return(SerializeInfoCore(info, name, ignoreInfo, logger)); }
public static Dictionary <string, string> SerializeInfo(NameValueCollection info, string name, IgnorePropertiesInfo ignoreInfo, ILogger logger) { Dictionary <string, string> result = null; if (info != null && info.Count != 0) { try { logger.BeginWriteObject(name); foreach (string key in info.AllKeys) { if (ignoreInfo != null && ignoreInfo.ShouldIgnore(key)) { if (result == null) { result = new Dictionary <string, string>(); } result[key] = info.Get(key); logger.WriteValue(key, RequestBodyFilter.ValueStripped); } else { logger.WriteValue(key, info.Get(key)); } } } finally { logger.EndWriteObject(name); } } return(result); }