private static int GetMediaTypeLength(string input, int startIndex, out MediaTypeHeaderValue parsedValue) { Contract.Requires(startIndex >= 0); parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return(0); } // Caller must remove leading whitespace. If not, we'll return 0. string mediaType = null; var mediaTypeLength = MediaTypeHeaderValue.GetMediaTypeExpressionLength(input, startIndex, out mediaType); if (mediaTypeLength == 0) { return(0); } var current = startIndex + mediaTypeLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); MediaTypeHeaderValue mediaTypeHeader = null; // If we're not done and we have a parameter delimiter, then we have a list of parameters. if ((current < input.Length) && (input[current] == ';')) { mediaTypeHeader = new MediaTypeHeaderValue(); mediaTypeHeader._mediaType = mediaType; current++; // skip delimiter. var parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';', mediaTypeHeader.Parameters); parsedValue = mediaTypeHeader; return(current + parameterLength - startIndex); } // We have a media type without parameters. mediaTypeHeader = new MediaTypeHeaderValue(); mediaTypeHeader._mediaType = mediaType; parsedValue = mediaTypeHeader; return(current - startIndex); }
private static int GetDispositionTypeLength(string input, int startIndex, out ContentDispositionHeaderValue parsedValue) { Contract.Requires(startIndex >= 0); parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return(0); } // Caller must remove leading whitespaces. If not, we'll return 0. string dispositionType = null; var dispositionTypeLength = GetDispositionTypeExpressionLength(input, startIndex, out dispositionType); if (dispositionTypeLength == 0) { return(0); } var current = startIndex + dispositionTypeLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); var contentDispositionHeader = new ContentDispositionHeaderValue(); contentDispositionHeader._dispositionType = dispositionType; // If we're not done and we have a parameter delimiter, then we have a list of parameters. if ((current < input.Length) && (input[current] == ';')) { current++; // skip delimiter. int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';', contentDispositionHeader.Parameters); parsedValue = contentDispositionHeader; return(current + parameterLength - startIndex); } // We have a ContentDisposition header without parameters. parsedValue = contentDispositionHeader; return(current - startIndex); }