mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-28 11:17:02 +02:00
* Create WireMock.Net.MimePart project * . * REFACTOR * ILRepack * -- * ... * x * x * . * fix * public class MimePartMatcher * shared * min * . * <!--<DelaySign>true</DelaySign>--> * Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
26 lines
945 B
C#
26 lines
945 B
C#
// Copyright © WireMock.Net
|
|
|
|
using System.Text.RegularExpressions;
|
|
using Stef.Validation;
|
|
using WireMock.Constants;
|
|
|
|
namespace WireMock.Util;
|
|
|
|
/// <summary>
|
|
/// https://en.wikipedia.org/wiki/HTTP
|
|
/// </summary>
|
|
internal static class HttpVersionParser
|
|
{
|
|
private static readonly Regex HttpVersionRegex = new(@"HTTP/(\d+(\.\d+)?(?!\.))", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled, RegexConstants.DefaultTimeout);
|
|
|
|
/// <summary>
|
|
/// Try to extract the version (as a string) from the protocol.
|
|
/// </summary>
|
|
/// <param name="protocol">The protocol, something like "HTTP/1.1" or "HTTP/2".</param>
|
|
/// <returns>The version ("1.1" or "2") if found and valid, else empty string.</returns>
|
|
internal static string Parse(string protocol)
|
|
{
|
|
var match = HttpVersionRegex.Match(Guard.NotNull(protocol));
|
|
return match.Success ? match.Groups[1].Value : string.Empty;
|
|
}
|
|
} |