diff --git a/src/RestSharp/Response/RestResponseExtensions.cs b/src/RestSharp/Response/RestResponseExtensions.cs index 4a039ed7b..32735f571 100644 --- a/src/RestSharp/Response/RestResponseExtensions.cs +++ b/src/RestSharp/Response/RestResponseExtensions.cs @@ -22,7 +22,7 @@ public static class RestResponseExtensions { /// Name of the header /// Header value or null if the header is not found in the response public static string? GetHeaderValue(this RestResponse response, string headerName) - => response.Headers?.FirstOrDefault(x => NameIs(x.Name, headerName))?.Value?.ToString(); + => response.Headers?.FirstOrDefault(x => NameIs(x.Name, headerName))?.Value.ToString(); /// /// Gets all the values of the header with the specified name. @@ -33,7 +33,29 @@ public static class RestResponseExtensions { public static string[] GetHeaderValues(this RestResponse response, string headerName) => response.Headers ?.Where(x => NameIs(x.Name, headerName)) - .Select(x => x.Value?.ToString() ?? "") + .Select(x => x.Value.ToString() ?? "") + .ToArray() ?? + []; + + /// + /// Gets the value of the content header with the specified name. + /// + /// Response object + /// Name of the header + /// Header value or null if the content header is not found in the response + public static string? GetContentHeaderValue(this RestResponse response, string headerName) + => response.ContentHeaders?.FirstOrDefault(x => NameIs(x.Name, headerName))?.Value.ToString(); + + /// + /// Gets all the values of the content header with the specified name. + /// + /// Response object + /// Name of the header + /// Array of header values or empty array if the content header is not found in the response + public static string[] GetContentHeaderValues(this RestResponse response, string headerName) + => response.ContentHeaders + ?.Where(x => NameIs(x.Name, headerName)) + .Select(x => x.Value.ToString() ?? "") .ToArray() ?? [];