private static Accept Parse(IList<ContentType> types) { var result = new Accept(); foreach (var type in types.Where(x => !x.MediaType.EndsWith("/*", StringComparison.OrdinalIgnoreCase))) { result.ContentTypes.Add(type); } var any = false; foreach (var type in types) { if (type.MediaType.Equals("*/*", StringComparison.OrdinalIgnoreCase)) { any = true; continue; } if (!type.MediaType.EndsWith("/*", StringComparison.OrdinalIgnoreCase)) { continue; } result.ContentTypes.Add(type); } if (any) { result.ContentTypes.Add(new ContentType("*/*")); } return result; }
public ActionResult ContentNegotiation(CultureInfo language) { if (null == language) { throw new ArgumentNullException("language"); } if (CultureInfo.InvariantCulture == language) { throw new ArgumentOutOfRangeException("language"); } language.SetCurrentCulture(); Accept accept = Request.Headers["Accept"]; return(accept.Negotiate(Request, GetType())); }
public void op_FromString_stringWithSingleAsterixContentType() { Assert.Equal(4, Accept.FromString("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2").ContentTypes.Count); }