Skip to content
Merged
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
26 changes: 24 additions & 2 deletions src/RestSharp/Response/RestResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class RestResponseExtensions {
/// <param name="headerName">Name of the header</param>
/// <returns>Header value or null if the header is not found in the response</returns>
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();

/// <summary>
/// Gets all the values of the header with the specified name.
Expand All @@ -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() ??
[];

/// <summary>
/// Gets the value of the content header with the specified name.
/// </summary>
/// <param name="response">Response object</param>
/// <param name="headerName">Name of the header</param>
/// <returns>Header value or null if the content header is not found in the response</returns>
public static string? GetContentHeaderValue(this RestResponse response, string headerName)
=> response.ContentHeaders?.FirstOrDefault(x => NameIs(x.Name, headerName))?.Value.ToString();

/// <summary>
/// Gets all the values of the content header with the specified name.
/// </summary>
/// <param name="response">Response object</param>
/// <param name="headerName">Name of the header</param>
/// <returns>Array of header values or empty array if the content header is not found in the response</returns>
public static string[] GetContentHeaderValues(this RestResponse response, string headerName)
=> response.ContentHeaders
?.Where(x => NameIs(x.Name, headerName))
.Select(x => x.Value.ToString() ?? "")
.ToArray() ??
[];

Expand Down