in src/Elastic.Transport/Responses/ResponseFactory.cs [25:104]
public abstract TResponse Create<TResponse>(
Endpoint endpoint,
BoundConfiguration boundConfiguration,
PostData? postData,
Exception? ex,
int? statusCode,
Dictionary<string, IEnumerable<string>>? headers,
Stream responseStream,
string? contentType,
long contentLength,
IReadOnlyDictionary<string, ThreadPoolStatistics>? threadPoolStats,
IReadOnlyDictionary<TcpState, int>? tcpStats
) where TResponse : TransportResponse, new();
/// <summary>
/// Create an instance of <typeparamref name="TResponse" /> from <paramref name="responseStream" />
/// </summary>
public abstract Task<TResponse> CreateAsync<TResponse>(
Endpoint endpoint,
BoundConfiguration boundConfiguration,
PostData? postData,
Exception? ex,
int? statusCode,
Dictionary<string, IEnumerable<string>>? headers,
Stream responseStream,
string? contentType,
long contentLength,
IReadOnlyDictionary<string, ThreadPoolStatistics>? threadPoolStats,
IReadOnlyDictionary<TcpState, int>? tcpStats,
CancellationToken cancellationToken = default
) where TResponse : TransportResponse, new();
internal static ApiCallDetails InitializeApiCallDetails(
Endpoint endpoint,
BoundConfiguration boundConfiguration,
PostData? postData,
Exception exception,
int? statusCode,
Dictionary<string, IEnumerable<string>> headers,
string contentType,
IReadOnlyDictionary<string,
ThreadPoolStatistics> threadPoolStats,
IReadOnlyDictionary<TcpState, int> tcpStats,
long contentLength)
{
var hasSuccessfulStatusCode = false;
var allowedStatusCodes = boundConfiguration.AllowedStatusCodes;
if (statusCode.HasValue)
{
if (allowedStatusCodes.Contains(-1) || allowedStatusCodes.Contains(statusCode.Value))
hasSuccessfulStatusCode = true;
else
hasSuccessfulStatusCode = boundConfiguration.ConnectionSettings
.StatusCodeToResponseSuccess(endpoint.Method, statusCode.Value);
}
// We don't validate the content-type (MIME type) for HEAD requests or responses that have no content (204 status code).
// Elastic Cloud responses to HEAD requests strip the content-type header so we want to avoid validation in that case.
var hasExpectedContentType = !MayHaveBody(statusCode, endpoint.Method, contentLength) || ValidateResponseContentType(boundConfiguration.Accept, contentType);
var details = new ApiCallDetails
{
HasSuccessfulStatusCode = hasSuccessfulStatusCode,
HasExpectedContentType = hasExpectedContentType,
OriginalException = exception,
HttpStatusCode = statusCode,
RequestBodyInBytes = postData?.WrittenBytes,
Uri = endpoint.Uri,
HttpMethod = endpoint.Method,
TcpStats = tcpStats,
ThreadPoolStats = threadPoolStats,
ResponseContentType = contentType,
TransportConfiguration = boundConfiguration.ConnectionSettings
};
if (headers is not null)
details.ParsedHeaders = new ReadOnlyDictionary<string, IEnumerable<string>>(headers);
return details;
}