/// <summary> /// Parses a chunk's size line into an HttpChunkSizeLine instance /// </summary> /// <param name="value"></param> /// <returns></returns> public static HttpChunkSizeLine Parse(string value) { // strip the CRLF from each line value = HttpUtils.StripCRLF(value); int size = 0; string extension = null; // if the size line includes a ';' then there is also an extension present int indexOfSep = value.IndexOf(';'); if (indexOfSep > 0) { // split the line on the ';' string szSize = value.Substring(0, indexOfSep); extension = value.Substring(++indexOfSep); szSize = HttpUtils.TrimLeadingAndTrailingSpaces(szSize); extension = HttpUtils.TrimLeadingAndTrailingSpaces(extension); // parse the size and extension from the line size = int.Parse(szSize, System.Globalization.NumberStyles.HexNumber); } else { // no extension because a lack of the ';' separator, just parse the size value = HttpUtils.TrimLeadingAndTrailingSpaces(value); size = int.Parse(value, System.Globalization.NumberStyles.HexNumber); } // return a new chunk instance return(new HttpChunkSizeLine(size, extension)); }
/// <summary> /// Intitializes a new instance of the HttpProtocolVersion class /// </summary> /// <param name="httpVersion">The version string to be represented</param> public HttpProtocolVersion(string value) { value = HttpUtils.StripCRLF(value); value = HttpUtils.TrimLeadingAndTrailingSpaces(value); string[] parts = value.Split('/'); this.Protocol = parts[0]; this.Version = parts[1]; }
/// <summary> /// Parses a string in the foramt 'Protocol/Version' into an HttpProtocolVersion instance /// </summary> /// <param name="value">The string to parse. May contain CRLF.</param> /// <returns></returns> public static HttpProtocolVersion Parse(string value) { value = HttpUtils.StripCRLF(value); value = HttpUtils.TrimLeadingAndTrailingSpaces(value); string[] parts = value.Split('/'); if (parts.Length == 1) { return(null); } return(new HttpProtocolVersion(parts[0], parts[1])); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static HttpHeader Parse(string value) { // strip the crlf if it's there value = HttpUtils.StripCRLF(value); // split it on the header token int indexOfDelimiter = value.IndexOf(':'); string headerName = value.Substring(0, indexOfDelimiter); string headerValue = value.Substring(++indexOfDelimiter); // trim the leading and trailing spaces from the fields headerName = HttpUtils.TrimLeadingAndTrailingSpaces(headerName); headerValue = HttpUtils.TrimLeadingAndTrailingSpaces(headerValue); // return a new header return(new HttpHeader(headerName, headerValue)); }
/// <summary> /// Parses a string in the format of 'Code SP Reason' into an HttpStatus instance /// </summary> /// <param name="value">The string to parse. May include the CRLF.</param> /// <returns></returns> public static HttpStatus Parse(string value) { value = HttpUtils.StripCRLF(value); value = HttpUtils.TrimLeadingAndTrailingSpaces(value); string code = null; string reason = null; int indexOfSP = value.IndexOf(' '); if (indexOfSP > 0) { code = value.Substring(0, indexOfSP); reason = value.Substring(++indexOfSP); } else { System.Diagnostics.Debug.WriteLine(string.Format("Failed to parse the HTTP Status {0}.", value)); code = value; } return(new HttpStatus((HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), code), reason)); }