CRUD through HTTP is a good step forward to using resources and becoming RESTful. Another step further into it is to make use of hypermedia-based services and the Restfulie gem allows you to do it very quickly.
if (ContainsQualifier(type))
{
var typeInfo = type.Split(';');
format = typeInfo[0].Trim();
qualifier = Convert.ToDouble(typeInfo[1].Split('=')[1], new CultureInfo("en-US"));
}
This gets an instance of "application/xml;image/png" which it then splits at the ; and then tries to resplit on =, however since there is no = at all, typeInfo[1] is out of bounds of the array.
System.IndexOutOfRangeExceptionIndex was outside the bounds of the array.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Restfulie.Server.Negotiation.AcceptHeaderToMediaType.ParseFormat(String type)
at Restfulie.Server.Negotiation.AcceptHeaderToMediaType.GetMediaType(String acceptHeader)
at Restfulie.Server.ActAsRestfulie.OnActionExecuting(ActionExecutingContext filterContext)
[TestFixture]
public class AcceptHeaderToMediaTypeTests
{
[Test]
public void shouldwork()
{
var mediaType = acceptHeader.GetMediaType("text/html,application/xhtml+xml,application/xml;image/png,image/jpeg,image/*;q=0.9,*/*;q=0.8");
}
Accept: text/html,application/xhtml+xml,application/xml;image/png,image/jpeg,image/;q=0.9,/*;q=0.8
This will crash
AcceptHeaderToMediaType private FormatPlusQualifier ParseFormat(string type)
This gets an instance of "application/xml;image/png" which it then splits at the ; and then tries to resplit on =, however since there is no = at all, typeInfo[1] is out of bounds of the array.
System.IndexOutOfRangeExceptionIndex was outside the bounds of the array.
System.IndexOutOfRangeException: Index was outside the bounds of the array. at Restfulie.Server.Negotiation.AcceptHeaderToMediaType.ParseFormat(String type) at Restfulie.Server.Negotiation.AcceptHeaderToMediaType.GetMediaType(String acceptHeader) at Restfulie.Server.ActAsRestfulie.OnActionExecuting(ActionExecutingContext filterContext)