public static bool TryParse(string statusLine, out IHttpStatusLine result) { Match statusLineMatch = Regex.Match(statusLine, @"^HTTP\/(\d+(?:\.\d+)?)\s*(\d+)\s*(.+?)$"); if (statusLineMatch.Success) { string protocolVersionStr = statusLineMatch.Groups[1].Value; string[] versionNumsStr = protocolVersionStr.Split('.'); int major = int.Parse(versionNumsStr[0]); int minor = versionNumsStr.Length > 1 ? int.Parse(versionNumsStr[1]) : 0; Version protocolVersion = new Version(major, minor); HttpStatusCode statusCode = HttpStatusCode.OK; if (int.TryParse(statusLineMatch.Groups[2].Value, out int statusCodeInt)) { statusCode = (HttpStatusCode)statusCodeInt; } string statusDescription = statusLineMatch.Groups[3].Value; result = new HttpStatusLine(protocolVersion, statusCode, statusDescription); } else { result = null; } return(result is object); }
private IHttpStatusLine GetStatusLine() { IHttpStatusLine statusLine = null; if (string.IsNullOrEmpty(bufferedLine)) { bufferedLine = reader.ReadLine(); if (HttpStatusLine.TryParse(bufferedLine, out statusLine)) { bufferedLine = string.Empty; } } return(statusLine); }
public IHttpStatusLine ReadStatusLine() { string statusLine = reader.ReadLine(); return(HttpStatusLine.Parse(statusLine)); }