Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp-refactor] Minor csharp refactor changes #1723

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace {{packageName}}.Client

foreach (var contentType in contentTypes)
{
if (IsJsonMime(contentType.ToLower()))
if (IsJsonMime(contentType))
return contentType;
}

Expand All @@ -229,6 +229,11 @@ namespace {{packageName}}.Client
return String.Join(",", accepts);
}

/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
/// JSON MIME examples:
Expand All @@ -241,8 +246,9 @@ namespace {{packageName}}.Client
/// <returns>Returns True if MIME type is json.</returns>
public static bool IsJsonMime(String mime)
{
var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json"));
if (String.IsNullOrWhiteSpace(mime)) return false;

return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static String SelectHeaderContentType(String[] contentTypes)

foreach (var contentType in contentTypes)
{
if (IsJsonMime(contentType.ToLower()))
if (IsJsonMime(contentType))
return contentType;
}

Expand All @@ -233,6 +233,11 @@ public static String SelectHeaderAccept(String[] accepts)
return String.Join(",", accepts);
}

/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
/// JSON MIME examples:
Expand All @@ -245,8 +250,9 @@ public static String SelectHeaderAccept(String[] accepts)
/// <returns>Returns True if MIME type is json.</returns>
public static bool IsJsonMime(String mime)
{
var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json"));
if (String.IsNullOrWhiteSpace(mime)) return false;

return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
}
}
}