예제 #1
0
    /// <summary>
    /// Reads an object from the specified HTTP content.
    /// </summary>
    public async Task <ServiceResult <object> > ReadHttpContentAsync(Type objectType, HttpContent?content, CancellationToken cancellationToken = default)
    {
        var contentType = content?.Headers.ContentType;

        if (contentType == null)
        {
            return(ServiceResult.Failure(HttpServiceErrors.CreateMissingContentType()));
        }

        var mediaType = contentType.MediaType ?? "";

        if (!IsSupportedMediaType(mediaType))
        {
            return(ServiceResult.Failure(HttpServiceErrors.CreateUnsupportedContentType(mediaType)));
        }

        return(await ReadHttpContentAsyncCore(objectType, content !, cancellationToken).ConfigureAwait(false));
    }
 public async Task MissingContentType()
 {
     await GetApiInfoInvalidResponse(
         _ => new HttpResponseMessage(HttpStatusCode.OK),
         ServiceErrors.InvalidResponse, HttpServiceErrors.CreateMissingContentType().Message);
 }