/// <summary> /// returns true if the string was parsed, false if the string wasn't valid /// </summary> /// <param name="httpVersionString"> /// A <see cref="System.String"/> /// </param> /// <param name="httpVersion"> /// A <see cref="HttpVersions"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> public static bool StringToHttpVersion(string httpVersionString, out HttpVersions httpVersion) { httpVersion = HttpVersions.Http10; // format is like "HTTP/1.1", so version comes after the slash string[] tokens = httpVersionString.Split('/'); if (tokens[0] != "HTTP") { Log.Information("Expected 'HTTP' got " + tokens[0]); return(false); } if (tokens[1] == "1.0") { httpVersion = HttpVersions.Http10; } else if (tokens[1] == "1.1") { httpVersion = HttpVersions.Http11; } else { throw new HttpVersionParsingException("unable to parse " + httpVersionString + " into a valid version"); } // we were able to parse the version return(true); }
private string Stringify(HttpVersions version) { switch (version) { case HttpVersions.HTTP1_0: return("HTTP/1.0"); case HttpVersions.HTTP1_1: return("HTTP/1.1"); case HttpVersions.HTTP2_0: return("HTTP/2.0"); default: return("HTTP/1.0"); } }
public static bool Contains(this HttpVersions @this, HttpVersions versions) => (@this & versions) != 0;